liblzma: Use lzma_memcmplen() in normal mode of LZMA.

Two locations were not changed yet because the simplest change
assumes that the initial "len" may be greater than "limit".
This commit is contained in:
Lasse Collin 2014-07-25 22:38:28 +03:00
parent f48fce093b
commit 544aaa3d13
1 changed files with 5 additions and 15 deletions

View File

@ -11,6 +11,7 @@
#include "lzma_encoder_private.h" #include "lzma_encoder_private.h"
#include "fastpos.h" #include "fastpos.h"
#include "memcmplen.h"
//////////// ////////////
@ -305,13 +306,9 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf,
continue; continue;
} }
uint32_t len_test; rep_lens[i] = lzma_memcmplen(buf, buf_back, 2, buf_avail);
for (len_test = 2; len_test < buf_avail
&& buf[len_test] == buf_back[len_test];
++len_test) ;
rep_lens[i] = len_test; if (rep_lens[i] > rep_lens[rep_max_index])
if (len_test > rep_lens[rep_max_index])
rep_max_index = i; rep_max_index = i;
} }
@ -568,11 +565,7 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
const uint8_t *const buf_back = buf - reps[0] - 1; const uint8_t *const buf_back = buf - reps[0] - 1;
const uint32_t limit = my_min(buf_avail_full, nice_len + 1); const uint32_t limit = my_min(buf_avail_full, nice_len + 1);
uint32_t len_test = 1; const uint32_t len_test = lzma_memcmplen(buf, buf_back, 1, limit) - 1;
while (len_test < limit && buf[len_test] == buf_back[len_test])
++len_test;
--len_test;
if (len_test >= 2) { if (len_test >= 2) {
lzma_lzma_state state_2 = state; lzma_lzma_state state_2 = state;
@ -612,10 +605,7 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
if (not_equal_16(buf, buf_back)) if (not_equal_16(buf, buf_back))
continue; continue;
uint32_t len_test; uint32_t len_test = lzma_memcmplen(buf, buf_back, 2, buf_avail);
for (len_test = 2; len_test < buf_avail
&& buf[len_test] == buf_back[len_test];
++len_test) ;
while (len_end < cur + len_test) while (len_end < cur + len_test)
coder->opts[++len_end].price = RC_INFINITY_PRICE; coder->opts[++len_end].price = RC_INFINITY_PRICE;