From 2b9bf9e672eed49de0d9b1f583d1f4b46395ae79 Mon Sep 17 00:00:00 2001 From: Mika Lindqvist Date: Sun, 19 Jun 2016 15:21:46 +0300 Subject: [PATCH] Don't update prev if old head is same as new. --- arch/x86/insert_string_sse.c | 7 +++++-- deflate_p.h | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/insert_string_sse.c b/arch/x86/insert_string_sse.c index 90c619a8..6d4ddaea 100644 --- a/arch/x86/insert_string_sse.c +++ b/arch/x86/insert_string_sse.c @@ -39,9 +39,12 @@ Pos insert_string_sse(deflate_state *const s, const Pos str, unsigned int count) ); #endif - ret = s->prev[(str+idx) & s->w_mask] = s->head[h & s->hash_mask]; - s->head[h & s->hash_mask] = str+idx; + if (s->head[h & s->hash_mask] != str+idx) { + s->prev[(str+idx) & s->w_mask] = s->head[h & s->hash_mask]; + s->head[h & s->hash_mask] = str+idx; + } } + ret = s->prev[(str+count-1) & s->w_mask]; return ret; } #endif diff --git a/deflate_p.h b/deflate_p.h index 9b45b091..4b8282d4 100644 --- a/deflate_p.h +++ b/deflate_p.h @@ -42,9 +42,12 @@ local inline Pos insert_string_c(deflate_state *const s, const Pos str, uInt cou for (idx = 0; idx < count; idx++) { UPDATE_HASH(s, s->ins_h, str+idx); - ret = s->prev[(str+idx) & s->w_mask] = s->head[s->ins_h]; - s->head[s->ins_h] = str+idx; + if (s->head[s->ins_h] != str+idx) { + s->prev[(str+idx) & s->w_mask] = s->head[s->ins_h]; + s->head[s->ins_h] = str+idx; + } } + ret = s->prev[(str+count-1) & s->w_mask]; return ret; } -- 2.47.2