From ce52acd7dc7a7afc83433f0f2212942eb3160abb Mon Sep 17 00:00:00 2001 From: Jun He Date: Fri, 24 Jun 2022 17:07:06 +0800 Subject: [PATCH] compress:check more bytes to reduce ZSTD_count call Comparing 4B instead of comparing 1B in ZSTD_noDict mode, thus it can avoid cases like match in match[ml] but mismatch in match[ml-3]..match[ml-1]. So the call count of ZSTD_count can be reduced. Signed-off-by: Jun He Change-Id: I3449ea423d5c8e8344f75341f19a2d1643c703f6 --- lib/compress/zstd_lazy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/compress/zstd_lazy.c b/lib/compress/zstd_lazy.c index e54b43c0c..3e2ee1dda 100644 --- a/lib/compress/zstd_lazy.c +++ b/lib/compress/zstd_lazy.c @@ -692,7 +692,8 @@ size_t ZSTD_HcFindBestMatch( if ((dictMode != ZSTD_extDict) || matchIndex >= dictLimit) { const BYTE* const match = base + matchIndex; assert(matchIndex >= dictLimit); /* ensures this is true if dictMode != ZSTD_extDict */ - if (match[ml] == ip[ml]) /* potentially better */ + /* read 4B starting from (match + ml + 1 - sizeof(U32)) */ + if (MEM_read32(match + ml - 3) == MEM_read32(ip + ml - 3)) /* potentially better */ currentMl = ZSTD_count(ip, match, iLimit); } else { const BYTE* const match = dictBase + matchIndex; @@ -1244,7 +1245,8 @@ size_t ZSTD_RowFindBestMatch( if ((dictMode != ZSTD_extDict) || matchIndex >= dictLimit) { const BYTE* const match = base + matchIndex; assert(matchIndex >= dictLimit); /* ensures this is true if dictMode != ZSTD_extDict */ - if (match[ml] == ip[ml]) /* potentially better */ + /* read 4B starting from (match + ml + 1 - sizeof(U32)) */ + if (MEM_read32(match + ml - 3) == MEM_read32(ip + ml - 3)) /* potentially better */ currentMl = ZSTD_count(ip, match, iLimit); } else { const BYTE* const match = dictBase + matchIndex; -- 2.47.2