Permalink
Browse files

romchu: Inline the bitstream_eof() function both times it is called.

It is a small overall performance gain for normal usage (2-3% for Super Smash Bros.) but more drastic when profiling (10-11% for SSB with the cProfile module).
  • Loading branch information...
1 parent 118b161 commit 3ad7319050e2ecbff1aece763cfd7b73dfe30dde @Plombo committed Jan 27, 2011
Showing with 4 additions and 6 deletions.
  1. +2 −1 romc.py
  2. +2 −5 romchu.py
View
@@ -31,14 +31,15 @@ def decompress(infile):
if __name__ == '__main__':
import sys, time
+ import cProfile
if len(sys.argv) != 3:
print 'Usage: %s infile outfile' % sys.argv[0]
sys.exit(1)
infile = open(sys.argv[1], 'rb')
start = time.clock()
- output = decompress(infile)
+ output = decompress(infile) # cProfile.run('output = decompress(infile)')
end = time.clock()
print 'Time: %.2f seconds' % (end - start)
View
@@ -165,7 +165,7 @@ def decompress(infile):
body_size = payload_bytes*8 + payload_bits - body_offset*8
bs = init_bitstream(payload_buf, body_offset, body_size)
- while not bitstream_eof(bs):
+ while (bs.bits_left + bs.first_byte_bits) != 0:
symbol = huf_lookup(bs, table1)
if symbol < 0x100:
@@ -282,9 +282,6 @@ def get_bits(bs, bits):
return accum >> (32-bits)
-def bitstream_eof(bs):
- return (bs.bits_left + bs.first_byte_bits == 0)
-
def free_bitstream(bs):
pass
@@ -342,7 +339,7 @@ def load_table(bs, symbols):
len_count[length] += 1
i += 1
- assert bitstream_eof(bs) # did not exhaust bitstream reading table
+ assert (bs.bits_left + bs.first_byte_bits) == 0 # did not exhaust bitstream reading table
# compute the first canonical Hufman code for each length
accum = 0

0 comments on commit 3ad7319

Please sign in to comment.