Mercurial > touhou
comparison pytouhou/utils/bitstream.pyx @ 252:b5c7369abd7c
Improve data reading perfs
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 22 Jan 2012 15:54:51 +0100 |
parents | fab7ad2f0d8b |
children | 2674c789e0c3 |
comparison
equal
deleted
inserted
replaced
251:4b549894ef6b | 252:b5c7369abd7c |
---|---|
13 ## | 13 ## |
14 | 14 |
15 cdef class BitStream: | 15 cdef class BitStream: |
16 cdef public io | 16 cdef public io |
17 cdef public int bits | 17 cdef public int bits |
18 cdef public int byte | 18 cdef public unsigned char byte |
19 | |
19 | 20 |
20 def __init__(BitStream self, io): | 21 def __init__(BitStream self, io): |
21 self.io = io | 22 self.io = io |
22 self.bits = 0 | 23 self.bits = 0 |
23 self.byte = 0 | 24 self.byte = 0 |
51 self.bits = 8 | 52 self.bits = 8 |
52 self.bits -= 1 | 53 self.bits -= 1 |
53 return (self.byte >> self.bits) & 0x01 | 54 return (self.byte >> self.bits) & 0x01 |
54 | 55 |
55 | 56 |
56 def read(BitStream self, nb_bits): | 57 cpdef unsigned int read(BitStream self, int nb_bits): |
57 cdef unsigned int value | 58 cdef unsigned int value = 0 |
58 value = 0 | 59 cdef int i |
60 | |
59 for i in range(nb_bits - 1, -1, -1): | 61 for i in range(nb_bits - 1, -1, -1): |
60 value |= self.read_bit() << i | 62 value |= self.read_bit() << i |
61 return value | 63 return value |
62 | 64 |
63 | 65 |