Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Consolidate PUT_BITS() calls
This actually doesn't seem to make any difference, but perhaps that's
because my packet corpus is heavily biased toward the random side, and
hence gets fewer history matches than it should. It certainly shouldn't
hurt, and may actually be a win in real life.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jan 8, 2015
1 parent 69d5794 commit 93de65d
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lzs.c
Expand Up @@ -238,11 +238,9 @@ int lzs_compress(unsigned char *dst, int dstlen, const unsigned char *src, int s
int length = longest_match_len;

if (offset < 0x80) {
PUT_BITS(2, 3);
PUT_BITS(7, offset);
PUT_BITS(9, 0x180 | offset);
} else {
PUT_BITS(2, 2);
PUT_BITS(11, offset);
PUT_BITS(13, 0x1000 | offset);
}
/* Output length */
if (length < 5)
Expand All @@ -251,11 +249,14 @@ int lzs_compress(unsigned char *dst, int dstlen, const unsigned char *src, int s
PUT_BITS(4, length + 7);
else {
length += 7;
while (length >= 15) {
PUT_BITS(4, 15);
length -= 15;
while (length >= 30) {
PUT_BITS(8, 0xff);
length -= 30;
}
PUT_BITS(4, length);
if (length >= 15)
PUT_BITS(8, 0xf0 + length - 15);
else
PUT_BITS(4, length);
}

/* Add byte(s) to the hash tables unless we're done */
Expand All @@ -275,10 +276,8 @@ int lzs_compress(unsigned char *dst, int dstlen, const unsigned char *src, int s
if (inpos < srclen)
PUT_BITS(9, src[inpos]);

/* End marker */
PUT_BITS(9, 0x180);
/* ... which must have its final bits flushed to the output. */
PUT_BITS(7, 0);
/* End marker, with 7 trailing zero bits to ensure that it's flushed. */
PUT_BITS(16, 0xc000);

return outpos;
}

0 comments on commit 93de65d

Please sign in to comment.