1 | /* |
1 | /* |
2 | * Copyright (c) 2000-2009 Marc Alexander Lehmann <schmorp@schmorp.de> |
2 | * Copyright (c) 2000-2010 Marc Alexander Lehmann <schmorp@schmorp.de> |
3 | * |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
5 | * tion, are permitted provided that the following conditions are met: |
5 | * tion, are permitted provided that the following conditions are met: |
6 | * |
6 | * |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
… | |
… | |
87 | #define expect_true(expr) expect ((expr) != 0, 1) |
87 | #define expect_true(expr) expect ((expr) != 0, 1) |
88 | |
88 | |
89 | /* |
89 | /* |
90 | * compressed format |
90 | * compressed format |
91 | * |
91 | * |
92 | * 000LLLLL <L+1> ; literal |
92 | * 000LLLLL <L+1> ; literal, L+1=1..33 octets |
93 | * LLLooooo oooooooo ; backref L |
93 | * LLLooooo oooooooo ; backref L+1=1..7 octets, o+1=1..4096 offset |
94 | * 111ooooo LLLLLLLL oooooooo ; backref L+7 |
94 | * 111ooooo LLLLLLLL oooooooo ; backref L+8 octets, o+1=1..4096 offset |
95 | * |
95 | * |
96 | */ |
96 | */ |
97 | |
97 | |
98 | unsigned int |
98 | unsigned int |
99 | lzf_compress (const void *const in_data, unsigned int in_len, |
99 | lzf_compress (const void *const in_data, unsigned int in_len, |
… | |
… | |
153 | && ref < ip /* the next test will actually take care of this, but this is faster */ |
153 | && ref < ip /* the next test will actually take care of this, but this is faster */ |
154 | #endif |
154 | #endif |
155 | && (off = ip - ref - 1) < MAX_OFF |
155 | && (off = ip - ref - 1) < MAX_OFF |
156 | && ip + 4 < in_end |
156 | && ip + 4 < in_end |
157 | && ref > (u8 *)in_data |
157 | && ref > (u8 *)in_data |
|
|
158 | && ref[2] == ip[2] |
158 | #if STRICT_ALIGN |
159 | #if STRICT_ALIGN |
159 | && ref[0] == ip[0] |
160 | && (ref[1] << 8) | ref[0] == (ip[1] << 8) | ip[0] |
160 | && ref[1] == ip[1] |
|
|
161 | && ref[2] == ip[2] |
|
|
162 | #else |
161 | #else |
163 | && *(u16 *)ref == *(u16 *)ip |
162 | && *(u16 *)ref == *(u16 *)ip |
164 | && ref[2] == ip[2] |
|
|
165 | #endif |
163 | #endif |
166 | ) |
164 | ) |
167 | { |
165 | { |
168 | /* match found at *ref++ */ |
166 | /* match found at *ref++ */ |
169 | unsigned int len = 2; |
167 | unsigned int len = 2; |