Skip to content

Commit

Permalink
Optimal LZSA1 compression
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel-marty authored Feb 27, 2023
1 parent 6b08bc3 commit 35ec6d7
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/matchfinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ static int lzsa_find_matches_at(lzsa_compressor *pCompressor, const int nOffset,
unsigned int match_pos;
lzsa_match *matchptr;
unsigned int nPrevOffset = 0;
unsigned char nV1OffsetFound[2] = { 0, 0 };

/**
* Find matches using intervals
Expand Down Expand Up @@ -281,14 +282,25 @@ static int lzsa_find_matches_at(lzsa_compressor *pCompressor, const int nOffset,
if (nMatchOffset <= MAX_OFFSET && nMatchOffset != nPrevOffset) {
if (pCompressor->format_version >= 2) {
matchptr->length = (const unsigned short)(ref >> (LCP_SHIFT + TAG_BITS));
matchptr->offset = (const unsigned short)nMatchOffset;
matchptr++;

nPrevOffset = nMatchOffset;
}
else {
matchptr->length = (const unsigned short)(ref >> LCP_SHIFT);
}
matchptr->offset = (const unsigned short)nMatchOffset;
matchptr++;
unsigned int nV1OffsetType = (nMatchOffset <= 256) ? 0 : 1;

nPrevOffset = nMatchOffset;
if (!nV1OffsetFound[nV1OffsetType]) {
matchptr->length = (const unsigned short)(ref >> LCP_SHIFT);
matchptr->offset = (const unsigned short)nMatchOffset;

if (matchptr->length < 256)
nV1OffsetFound[nV1OffsetType] = 1;
matchptr++;

nPrevOffset = nMatchOffset;
}
}
}
}

Expand Down

0 comments on commit 35ec6d7

Please sign in to comment.