aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Ivanov <SaveTheRbtz@GMail.com>2018-10-02 07:28:37 -0700
committerEugene Kliuchnikov <eustas@google.com>2018-10-02 16:28:37 +0200
commitc94c6f805c881b2a67540f5953a59d963d87a7f8 (patch)
tree631703e7f946341e6c68d577ad47e80feaa64c65
parent9402ac5c08806f4ba400bc390420c29ddd78ecd1 (diff)
downloadbrotli-c94c6f805c881b2a67540f5953a59d963d87a7f8.zip
brotli-c94c6f805c881b2a67540f5953a59d963d87a7f8.tar.gz
brotli-c94c6f805c881b2a67540f5953a59d963d87a7f8.tar.bz2
tools/brotli: improve window size autodetect (#710)
Window size is defined as: `(1 << BROTLI_PARAM_LGWIN) - 16` in `c/include/brotli/encode.h` Therefore we should probably take these 16 bytes into account. Done basic manual testing: $ python3 -c 'print ("A"*2046)' > t $ bazel run -- //:brotli -w 0 -f -o $(realpath t).br $(realpath ./t) $ python3 research/brotlidump.py t.br |& fgrep WSIZE 0000 c1 1000001 WSIZE windowsize=(1<<12)-16=4080 New version properly detects window size of `4080`, while previous one used `2032`: $ python3 research/brotlidump.py t.br |& fgrep WSIZE 0000 b1 0110001 WSIZE windowsize=(1<<11)-16=2032
-rw-r--r--c/tools/brotli.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/c/tools/brotli.c b/c/tools/brotli.c
index ea4fdac..ce05b64 100644
--- a/c/tools/brotli.c
+++ b/c/tools/brotli.c
@@ -943,10 +943,9 @@ static BROTLI_BOOL CompressFiles(Context* context) {
uint32_t lgwin = DEFAULT_LGWIN;
/* Use file size to limit lgwin. */
if (context->input_file_length >= 0) {
- int32_t size = 1 << BROTLI_MIN_WINDOW_BITS;
lgwin = BROTLI_MIN_WINDOW_BITS;
- while (size < context->input_file_length) {
- size <<= 1;
+ while (BROTLI_MAX_BACKWARD_LIMIT(lgwin) <
+ (uint64_t)context->input_file_length) {
lgwin++;
if (lgwin == BROTLI_MAX_WINDOW_BITS) break;
}