Mercurial > touhou
comparison pytouhou/utils/lzss.pyx @ 367:2674c789e0c3
Various optimizations
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 10 Jul 2012 00:25:08 +0200 |
parents | b5c7369abd7c |
children | 71cd4461bb7f |
comparison
equal
deleted
inserted
replaced
366:7dc012f631dc | 367:2674c789e0c3 |
---|---|
20 unsigned int dictionary_size=0x2000, | 20 unsigned int dictionary_size=0x2000, |
21 unsigned int offset_size=13, | 21 unsigned int offset_size=13, |
22 unsigned int length_size=4, | 22 unsigned int length_size=4, |
23 unsigned int minimum_match_length=3): | 23 unsigned int minimum_match_length=3): |
24 cdef unsigned int i, ptr, dictionary_head, offset, length | 24 cdef unsigned int i, ptr, dictionary_head, offset, length |
25 cdef unsigned char flag, byte, *out_data, *dictionary | 25 cdef unsigned char byte, *out_data, *dictionary |
26 cdef bytes _out_data | 26 cdef bytes _out_data |
27 | 27 |
28 out_data = <unsigned char*> malloc(size) | 28 out_data = <unsigned char*> malloc(size) |
29 dictionary = <unsigned char*> calloc(dictionary_size, 1) | 29 dictionary = <unsigned char*> calloc(dictionary_size, 1) |
30 dictionary_head, ptr = 1, 0 | 30 dictionary_head, ptr = 1, 0 |
31 | 31 |
32 while ptr < size: | 32 while ptr < size: |
33 flag = bitstream.read_bit() | 33 if bitstream.read_bit(): |
34 if flag: | |
35 # The `flag` bit is set, indicating the upcoming chunk of data is a literal | 34 # The `flag` bit is set, indicating the upcoming chunk of data is a literal |
36 # Add it to the uncompressed file, and store it in the dictionary | 35 # Add it to the uncompressed file, and store it in the dictionary |
37 byte = bitstream.read(8) | 36 byte = bitstream.read(8) |
38 dictionary[dictionary_head] = byte | 37 dictionary[dictionary_head] = byte |
39 dictionary_head = (dictionary_head + 1) % dictionary_size | 38 dictionary_head = (dictionary_head + 1) % dictionary_size |