Skip to content

Commit

Permalink
Add an option for zstd long distance matching compression
Browse files Browse the repository at this point in the history
The behavior is supposed to match the --long[=#] option of zstd binary.
  • Loading branch information
kontura authored and ffesti committed Jan 21, 2022
1 parent 1fdf660 commit c624966
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions rpmio/rpmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,8 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode)
char *te = t + sizeof(stdio) - 2;
int c;
int threads = 0;
int windowlog = 27;
int longdist = 0;

switch ((c = *s++)) {
case 'a':
Expand Down Expand Up @@ -1094,6 +1096,22 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode)
threads = -1;
}
continue;
case 'L':
c = *s++;
longdist = 1;
if (c >= (int)'0' && c <= (int)'9') {
windowlog = strtol(s-1, (char **)&s, 10);
ZSTD_bounds bounds = ZSTD_cParam_getBounds(ZSTD_c_windowLog);
if (windowlog < bounds.lowerBound){
windowlog = bounds.lowerBound;
rpmlog(RPMLOG_WARNING, "Invalid long distance matching window log for zstd. Using %i instead.\n", bounds.lowerBound);
}
if (windowlog > bounds.upperBound) {
windowlog = bounds.upperBound;
rpmlog(RPMLOG_WARNING, "Invalid long distance matching window log for zstd. Using %i instead.\n", bounds.upperBound);
}
}
continue;
default:
if (c >= (int)'0' && c <= (int)'9') {
level = strtol(s-1, (char **)&s, 10);
Expand Down Expand Up @@ -1132,6 +1150,13 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode)
goto err;
}

if (longdist) {
if (ZSTD_isError(ZSTD_CCtx_setParameter(_stream, ZSTD_c_enableLongDistanceMatching, longdist))
|| ZSTD_isError(ZSTD_CCtx_setParameter(_stream, ZSTD_c_windowLog, windowlog))) {
goto err;
}
}

threads = get_compression_threads(threads);
if (threads > 0) {
if (ZSTD_isError (ZSTD_CCtx_setParameter(_stream, ZSTD_c_nbWorkers, threads)))
Expand Down

0 comments on commit c624966

Please sign in to comment.