Skip to content

Commit b880f20

Browse files
authored
Merge pull request #4171 from facebook/lvl3_ratio+
Improve compression ratio of levels 3 & 4
2 parents 18a4219 + 41d870f commit b880f20

File tree

5 files changed

+328
-316
lines changed

5 files changed

+328
-316
lines changed

.github/workflows/commit.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ on:
33
push:
44
branches:
55
- dev
6+
pull_request:
7+
branches:
8+
- dev
9+
610
permissions: read-all
11+
712
jobs:
813
short-tests-0:
914
runs-on: ubuntu-latest
@@ -27,6 +32,7 @@ jobs:
2732
make -j regressiontest; make clean
2833
make shortest; make clean
2934
make cxxtest; make clean
35+
3036
short-tests-1:
3137
runs-on: ubuntu-latest
3238
services:
@@ -49,6 +55,7 @@ jobs:
4955
make aarch64build V=1; make clean
5056
make -C tests test-legacy test-longmatch; make clean
5157
make -C lib libzstd-nomt; make clean
58+
5259
regression-test:
5360
runs-on: ubuntu-latest
5461
services:

lib/compress/zstd_double_fast.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,23 @@ size_t ZSTD_compressBlock_doubleFast_noDict_generic(
252252

253253
_search_next_long:
254254

255-
/* check prefix long +1 match */
256-
if (idxl1 > prefixLowestIndex) {
257-
if (MEM_read64(matchl1) == MEM_read64(ip1)) {
255+
/* short match found: let's check for a longer one */
256+
mLength = ZSTD_count(ip+4, matchs0+4, iend) + 4;
257+
offset = (U32)(ip - matchs0);
258+
259+
/* check long match at +1 position */
260+
if ((idxl1 > prefixLowestIndex) && (MEM_read64(matchl1) == MEM_read64(ip1))) {
261+
size_t const l1len = ZSTD_count(ip1+8, matchl1+8, iend) + 8;
262+
if (l1len > mLength) {
263+
/* use the long match instead */
258264
ip = ip1;
259-
mLength = ZSTD_count(ip+8, matchl1+8, iend) + 8;
265+
mLength = l1len;
260266
offset = (U32)(ip-matchl1);
261-
while (((ip>anchor) & (matchl1>prefixLowest)) && (ip[-1] == matchl1[-1])) { ip--; matchl1--; mLength++; } /* catch up */
262-
goto _match_found;
267+
matchs0 = matchl1;
263268
}
264269
}
265270

266-
/* if no long +1 match, explore the short match we found */
267-
mLength = ZSTD_count(ip+4, matchs0+4, iend) + 4;
268-
offset = (U32)(ip - matchs0);
269-
while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* catch up */
271+
while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* complete backward */
270272

271273
/* fall-through */
272274

tests/fuzz/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ fuzz-*.log
2323
rt_lib_*
2424
d_lib_*
2525
crash-*
26+
decompress_cross_format
27+
generate_sequences
2628

2729
# misc
2830
trace

0 commit comments

Comments
 (0)