24
24
#include "tdString.h"
25
25
#include "td64_internal.h"
26
26
27
- #define STRING_LIMIT 9 // for 128+ values set to 17
28
- #define EXTENDED_STRING_LENGTH_BITS 3 // for 128+ values, use 4
29
27
#define MAX_STRING_MODE_EXTENDED_VALUES 512
30
28
31
29
static inline void esmOutputBits (unsigned char * outValsT , const uint32_t nBits , const uint32_t bitVal , uint32_t * nextOutIx , uint32_t * nextOutBit )
@@ -59,7 +57,10 @@ int32_t encodeExtendedStringMode(const unsigned char *inVals, unsigned char *out
59
57
unsigned char outValsT [MAX_STRING_MODE_EXTENDED_VALUES ];
60
58
uint32_t maxUniquesExceeded = 0 ;
61
59
uint32_t highBitClear ;
62
-
60
+ // smaller values compress slightly better with string limit of 9 versus 17
61
+ const uint32_t string_limit = nValuesMax <=64 ? 9 : 17 ;
62
+ const uint32_t extended_string_length_bits = nValuesMax <=64 ? 3 : 4 ;
63
+
63
64
if (nValuesMax > MAX_STRING_MODE_EXTENDED_VALUES )
64
65
return -1 ;
65
66
nextOutIx = 0 ; // start of encoding in outValsT
@@ -191,8 +192,8 @@ int32_t encodeExtendedStringMode(const unsigned char *inVals, unsigned char *out
191
192
uint32_t strLimit = inPos - 1 - twoValsPos ; // don't take string past current input pos
192
193
if (nValuesMax - strPos < strLimit )
193
194
strLimit = nValuesMax - strPos ; // don't go past end of input
194
- if (strLimit > STRING_LIMIT - 2 )
195
- strLimit = STRING_LIMIT - 2 ;
195
+ if (strLimit > string_limit - 2 )
196
+ strLimit = string_limit - 2 ;
196
197
197
198
uint32_t strCount = 0 ;
198
199
while (strCount ++ < strLimit && inVals [strPos ] == inVals [twoValsPos ])
@@ -201,7 +202,7 @@ int32_t encodeExtendedStringMode(const unsigned char *inVals, unsigned char *out
201
202
twoValsPos ++ ;
202
203
}
203
204
// output 11 plus string length bits
204
- esmOutputBits (outValsT , 2 + EXTENDED_STRING_LENGTH_BITS , 3 | ((strCount - 1 )<<2 ), & nextOutIx , & nextOutBit );
205
+ esmOutputBits (outValsT , 2 + extended_string_length_bits , 3 | ((strCount - 1 )<<2 ), & nextOutIx , & nextOutBit );
205
206
// output the position of string
206
207
if (encodingBits512 [inPos - 1 ] > 8 )
207
208
{
@@ -313,6 +314,8 @@ int32_t decodeExtendedStringMode(const unsigned char *inVals, unsigned char *out
313
314
unsigned char uncompressedUniques [MAX_UNIQUES_EXTENDED_STRING_MODE ];\
314
315
uint32_t secondByte = inVals [1 ]; // bits= 0:5 nUniques 6 first encoding bit 7 compressed or not
315
316
uint32_t nUniquesIn = (secondByte & 0x3f ) + 1 ;
317
+ // smaller values compress slightly better with string limit of 9 versus 17
318
+ const uint32_t extended_string_length_bits = nOriginalValues <=64 ? 3 : 4 ;
316
319
317
320
// process one of three encodings:
318
321
// 0 new unique value
@@ -405,7 +408,7 @@ int32_t decodeExtendedStringMode(const unsigned char *inVals, unsigned char *out
405
408
bitPos = 0 ;
406
409
}
407
410
// multi-character string: length, then location of values in bits needed to code current pos
408
- dsmGetBits2 (inVals , EXTENDED_STRING_LENGTH_BITS , & thisInVal , & thisVal , & bitPos , & theBits );
411
+ dsmGetBits2 (inVals , extended_string_length_bits , & thisInVal , & thisVal , & bitPos , & theBits );
409
412
uint32_t stringLen = (uint32_t )theBits + 2 ;
410
413
assert (stringLen <= STRING_LIMIT );
411
414
uint32_t nPosBits = encodingBits512 [nextOutVal ];
0 commit comments