From 592bc14ed14c4320b1c0b42e718b136e45fe1543 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 15 Aug 2021 10:49:09 +1000 Subject: [PATCH] Have std/deflate allow non-compact dst history MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #52 On a mid-range x86_64 laptop (2016, Skylake): name old speed new speed delta wuffs_deflate_decode_1k_full_init/clang9 101MB/s ± 1% 100MB/s ± 1% -1.22% (p=0.000 n=9+9) wuffs_deflate_decode_1k_part_init/clang9 119MB/s ± 1% 119MB/s ± 1% ~ (p=0.139 n=8+9) wuffs_deflate_decode_10k_full_init/clang9 221MB/s ± 1% 210MB/s ± 1% -4.94% (p=0.000 n=9+9) wuffs_deflate_decode_10k_part_init/clang9 225MB/s ± 3% 215MB/s ± 1% -4.33% (p=0.000 n=10+8) wuffs_deflate_decode_100k_just_one_read/clang9 290MB/s ± 0% 284MB/s ± 1% -2.26% (p=0.000 n=8+9) wuffs_deflate_decode_100k_many_big_reads/clang9 188MB/s ± 3% 177MB/s ± 1% -5.78% (p=0.000 n=9+10) wuffs_deflate_decode_1k_full_init/gcc10 101MB/s ± 0% 97MB/s ± 1% -3.65% (p=0.000 n=8+9) wuffs_deflate_decode_1k_part_init/gcc10 119MB/s ± 1% 113MB/s ± 2% -4.65% (p=0.000 n=9+9) wuffs_deflate_decode_10k_full_init/gcc10 214MB/s ± 3% 224MB/s ± 1% +4.83% (p=0.000 n=10+10) wuffs_deflate_decode_10k_part_init/gcc10 222MB/s ± 1% 231MB/s ± 1% +4.03% (p=0.000 n=9+10) wuffs_deflate_decode_100k_just_one_read/gcc10 281MB/s ± 2% 297MB/s ± 0% +5.78% (p=0.000 n=9+9) wuffs_deflate_decode_100k_many_big_reads/gcc10 184MB/s ± 0% 194MB/s ± 0% +5.85% (p=0.000 n=10+8) mimic_deflate_decode_1k_full_init 138MB/s ± 1% 138MB/s ± 0% ~ (p=0.546 n=9+9) mimic_deflate_decode_10k_full_init 156MB/s ± 2% 156MB/s ± 0% ~ (p=0.387 n=9+9) mimic_deflate_decode_100k_just_one_read 191MB/s ± 1% 190MB/s ± 2% -0.94% (p=0.004 n=9+10) mimic_deflate_decode_100k_many_big_reads 147MB/s ± 1% 147MB/s ± 1% ~ (p=0.356 n=9+10) wuffs_gzip_decode_10k/clang9 220MB/s ± 1% 209MB/s ± 1% -5.29% (p=0.000 n=10+9) wuffs_gzip_decode_100k/clang9 283MB/s ± 2% 279MB/s ± 1% -1.47% (p=0.002 n=10+10) wuffs_gzip_decode_10k/gcc10 218MB/s ± 1% 214MB/s ± 2% -1.76% (p=0.000 n=9+10) wuffs_gzip_decode_100k/gcc10 274MB/s ± 0% 264MB/s ± 2% -3.61% (p=0.000 n=7+10) mimic_gzip_decode_10k 131MB/s ± 2% 132MB/s ± 0% +0.81% (p=0.000 n=10+8) mimic_gzip_decode_100k 156MB/s ± 0% 156MB/s ± 1% ~ (p=0.423 n=8+9) wuffs_zlib_decode_10k/clang9 223MB/s ± 2% 209MB/s ± 2% -6.41% (p=0.000 n=10+10) wuffs_zlib_decode_100k/clang9 285MB/s ± 0% 280MB/s ± 0% -1.87% (p=0.000 n=8+9) wuffs_zlib_decode_10k/gcc10 235MB/s ± 0% 215MB/s ± 1% -8.22% (p=0.000 n=10+9) wuffs_zlib_decode_100k/gcc10 293MB/s ± 0% 268MB/s ± 1% -8.38% (p=0.000 n=8+10) mimic_zlib_decode_10k 145MB/s ± 1% 145MB/s ± 1% -0.45% (p=0.004 n=9+9) mimic_zlib_decode_100k 175MB/s ± 1% 174MB/s ± 0% ~ (p=0.055 n=10+8) wuffs_png_decode_image_19k_8bpp/clang9 142MB/s ± 1% 152MB/s ± 1% +6.98% (p=0.000 n=9+9) wuffs_png_decode_image_40k_24bpp/clang9 172MB/s ± 0% 170MB/s ± 0% -1.63% (p=0.000 n=8+9) wuffs_png_decode_image_77k_8bpp/clang9 504MB/s ± 2% 540MB/s ± 1% +7.28% (p=0.000 n=9+10) wuffs_png_decode_image_552k_32bpp_ignore_checksum/clang9 462MB/s ± 1% 470MB/s ± 0% +1.57% (p=0.000 n=9+10) wuffs_png_decode_image_552k_32bpp_verify_checksum/clang9 445MB/s ± 1% 451MB/s ± 0% +1.49% (p=0.000 n=8+10) wuffs_png_decode_image_4002k_24bpp/clang9 175MB/s ± 3% 175MB/s ± 1% ~ (p=0.356 n=9+10) wuffs_png_decode_image_19k_8bpp/gcc10 150MB/s ± 0% 153MB/s ± 1% +2.03% (p=0.000 n=10+10) wuffs_png_decode_image_40k_24bpp/gcc10 186MB/s ± 0% 186MB/s ± 0% ~ (p=0.408 n=10+8) wuffs_png_decode_image_77k_8bpp/gcc10 543MB/s ± 0% 542MB/s ± 0% -0.23% (p=0.019 n=9+9) wuffs_png_decode_image_552k_32bpp_ignore_checksum/gcc10 478MB/s ± 1% 498MB/s ± 0% +4.12% (p=0.000 n=10+9) wuffs_png_decode_image_552k_32bpp_verify_checksum/gcc10 451MB/s ± 4% 476MB/s ± 0% +5.37% (p=0.000 n=10+9) wuffs_png_decode_image_4002k_24bpp/gcc10 185MB/s ± 2% 190MB/s ± 1% +2.78% (p=0.000 n=10+9) mimic_png_decode_image_19k_8bpp 63.0MB/s ± 0% 62.9MB/s ± 1% ~ (p=0.673 n=8+9) mimic_png_decode_image_40k_24bpp 78.7MB/s ± 0% 78.9MB/s ± 0% ~ (p=0.059 n=9+8) mimic_png_decode_image_77k_8bpp 192MB/s ± 1% 193MB/s ± 3% +0.44% (p=0.028 n=10+9) mimic_png_decode_image_552k_32bpp_verify_checksum 157MB/s ± 0% 158MB/s ± 1% ~ (p=0.053 n=10+9) mimic_png_decode_image_4002k_24bpp 113MB/s ± 1% 113MB/s ± 1% ~ (p=0.053 n=10+9) --- release/c/wuffs-unsupported-snapshot.c | 24 ++++++++++ std/deflate/decode_deflate.wuffs | 9 ++++ std/deflate/decode_huffman_bmi2.wuffs | 7 +++ std/deflate/decode_huffman_fast32.wuffs | 7 +++ std/deflate/decode_huffman_fast64.wuffs | 7 +++ std/deflate/decode_huffman_slow.wuffs | 1 + test/c/std/gzip.c | 60 +++++++++++++++++++++++++ 7 files changed, 115 insertions(+) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index b2deb118..dbcefb0b 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -7103,6 +7103,7 @@ struct wuffs_deflate__decoder__struct { uint32_t f_bits; uint32_t f_n_bits; + uint64_t f_transformed_history_count; uint32_t f_history_index; uint32_t f_n_huffs_bits[2]; bool f_end_of_block; @@ -25758,6 +25759,7 @@ wuffs_deflate__decoder__transform_io( } goto ok; } + wuffs_base__u64__sat_add_indirect(&self->private_impl.f_transformed_history_count, wuffs_base__io__count_since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)))); wuffs_deflate__decoder__add_history(self, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst)); status = v_status; WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); @@ -26645,6 +26647,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2( uint32_t v_dist_minus_1 = 0; uint32_t v_hlen = 0; uint32_t v_hdist = 0; + uint32_t v_hdist_adjustment = 0; uint8_t* iop_a_dst = NULL; uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -26678,6 +26681,11 @@ wuffs_deflate__decoder__decode_huffman_bmi2( v_n_bits = self->private_impl.f_n_bits; v_lmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1); v_dmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1); + if (self->private_impl.f_transformed_history_count < (a_dst ? a_dst->meta.pos : 0)) { + status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position); + goto exit; + } + v_hdist_adjustment = ((uint32_t)(((self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0)) & 4294967295))); label__loop__continue:; while ((((uint64_t)(io2_a_dst - iop_a_dst)) >= 266) && (((uint64_t)(io2_a_src - iop_a_src)) >= 8)) { v_bits |= ((uint64_t)(wuffs_base__peek_u64le__no_bounds_check(iop_a_src) << (v_n_bits & 63))); @@ -26768,6 +26776,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2( v_hlen = v_length; v_length = 0; } + v_hdist += v_hdist_adjustment; if (self->private_impl.f_history_index < v_hdist) { status = wuffs_base__make_status(wuffs_deflate__error__bad_distance); goto exit; @@ -26852,6 +26861,7 @@ wuffs_deflate__decoder__decode_huffman_fast32( uint32_t v_dist_minus_1 = 0; uint32_t v_hlen = 0; uint32_t v_hdist = 0; + uint32_t v_hdist_adjustment = 0; uint8_t* iop_a_dst = NULL; uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -26885,6 +26895,11 @@ wuffs_deflate__decoder__decode_huffman_fast32( v_n_bits = self->private_impl.f_n_bits; v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1); v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1); + if (self->private_impl.f_transformed_history_count < (a_dst ? a_dst->meta.pos : 0)) { + status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position); + goto exit; + } + v_hdist_adjustment = ((uint32_t)(((self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0)) & 4294967295))); label__loop__continue:; while ((((uint64_t)(io2_a_dst - iop_a_dst)) >= 266) && (((uint64_t)(io2_a_src - iop_a_src)) >= 12)) { if (v_n_bits < 15) { @@ -27027,6 +27042,7 @@ wuffs_deflate__decoder__decode_huffman_fast32( v_hlen = v_length; v_length = 0; } + v_hdist += v_hdist_adjustment; if (self->private_impl.f_history_index < v_hdist) { status = wuffs_base__make_status(wuffs_deflate__error__bad_distance); goto exit; @@ -27110,6 +27126,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default( uint32_t v_dist_minus_1 = 0; uint32_t v_hlen = 0; uint32_t v_hdist = 0; + uint32_t v_hdist_adjustment = 0; uint8_t* iop_a_dst = NULL; uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -27143,6 +27160,11 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default( v_n_bits = self->private_impl.f_n_bits; v_lmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1); v_dmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1); + if (self->private_impl.f_transformed_history_count < (a_dst ? a_dst->meta.pos : 0)) { + status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position); + goto exit; + } + v_hdist_adjustment = ((uint32_t)(((self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0)) & 4294967295))); label__loop__continue:; while ((((uint64_t)(io2_a_dst - iop_a_dst)) >= 266) && (((uint64_t)(io2_a_src - iop_a_src)) >= 8)) { v_bits |= ((uint64_t)(wuffs_base__peek_u64le__no_bounds_check(iop_a_src) << (v_n_bits & 63))); @@ -27233,6 +27255,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default( v_hlen = v_length; v_length = 0; } + v_hdist += v_hdist_adjustment; if (self->private_impl.f_history_index < v_hdist) { status = wuffs_base__make_status(wuffs_deflate__error__bad_distance); goto exit; @@ -27567,6 +27590,7 @@ wuffs_deflate__decoder__decode_huffman_slow( v_hlen = v_length; v_length = 0; } + v_hdist += ((uint32_t)((((uint64_t)(self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0))) & 4294967295))); if (self->private_impl.f_history_index < v_hdist) { status = wuffs_base__make_status(wuffs_deflate__error__bad_distance); goto exit; diff --git a/std/deflate/decode_deflate.wuffs b/std/deflate/decode_deflate.wuffs index 428890c0..c24a4d5e 100644 --- a/std/deflate/decode_deflate.wuffs +++ b/std/deflate/decode_deflate.wuffs @@ -70,6 +70,14 @@ pub struct decoder? implements base.io_transformer( bits : base.u32, n_bits : base.u32, + // transformed_history_count is the number of bytes written to the history + // ringbuffer due to calling transform_io. It excludes any pre-history + // written by explicit calls to add_history. It also excludes any bytes + // decoded from the final transform_io call (the one that doesn't suspend) + // as there is no further need for tracking history (for resolving back- + // references) once the decoding completes. + transformed_history_count : base.u64, + // history_index indexes the history array, defined below. history_index : base.u32, @@ -211,6 +219,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf if not status.is_suspension() { return status } + this.transformed_history_count ~sat+= args.dst.count_since(mark: mark) // TODO: should "since" be "since!", as the return value lets you // modify the state of args.dst, so future mutations (via the slice) // can change the veracity of any args.dst assertions? diff --git a/std/deflate/decode_huffman_bmi2.wuffs b/std/deflate/decode_huffman_bmi2.wuffs index 991cee81..d3ce5dc2 100644 --- a/std/deflate/decode_huffman_bmi2.wuffs +++ b/std/deflate/decode_huffman_bmi2.wuffs @@ -35,6 +35,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader) var dist_minus_1 : base.u32[..= 0x7FFF] var hlen : base.u32[..= 0x7FFF] var hdist : base.u32 + var hdist_adjustment : base.u32 if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) { return "#internal error: inconsistent n_bits" @@ -46,6 +47,11 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader) lmask = ((1 as base.u64) << this.n_huffs_bits[0]) - 1 dmask = ((1 as base.u64) << this.n_huffs_bits[1]) - 1 + if this.transformed_history_count < args.dst.history_position() { + return base."#bad I/O position" + } + hdist_adjustment = ((this.transformed_history_count - args.dst.history_position()) & 0xFFFF_FFFF) as base.u32 + // Check up front, on each iteration, that we have enough buffer space to // both read (8 bytes) and write (266 bytes) as much as we need to. Doing // this check once (per iteration), up front, removes the need to check @@ -209,6 +215,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader) hlen = length length = 0 } + hdist ~mod+= hdist_adjustment if this.history_index < hdist { return "#bad distance" } diff --git a/std/deflate/decode_huffman_fast32.wuffs b/std/deflate/decode_huffman_fast32.wuffs index 543b074e..27523141 100644 --- a/std/deflate/decode_huffman_fast32.wuffs +++ b/std/deflate/decode_huffman_fast32.wuffs @@ -32,6 +32,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader var dist_minus_1 : base.u32[..= 0x7FFF] var hlen : base.u32[..= 0x7FFF] var hdist : base.u32 + var hdist_adjustment : base.u32 if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) { return "#internal error: inconsistent n_bits" @@ -43,6 +44,11 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader lmask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1 dmask = ((1 as base.u32) << this.n_huffs_bits[1]) - 1 + if this.transformed_history_count < args.dst.history_position() { + return base."#bad I/O position" + } + hdist_adjustment = ((this.transformed_history_count - args.dst.history_position()) & 0xFFFF_FFFF) as base.u32 + // Check up front, on each iteration, that we have enough buffer space to // both read (12 bytes) and write (266 bytes) as much as we need to. Doing // this check once (per iteration), up front, removes the need to check @@ -314,6 +320,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader hlen = length length = 0 } + hdist ~mod+= hdist_adjustment if this.history_index < hdist { return "#bad distance" } diff --git a/std/deflate/decode_huffman_fast64.wuffs b/std/deflate/decode_huffman_fast64.wuffs index a7dc7310..0a8cc8a3 100644 --- a/std/deflate/decode_huffman_fast64.wuffs +++ b/std/deflate/decode_huffman_fast64.wuffs @@ -34,6 +34,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader var dist_minus_1 : base.u32[..= 0x7FFF] var hlen : base.u32[..= 0x7FFF] var hdist : base.u32 + var hdist_adjustment : base.u32 if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) { return "#internal error: inconsistent n_bits" @@ -45,6 +46,11 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader lmask = ((1 as base.u64) << this.n_huffs_bits[0]) - 1 dmask = ((1 as base.u64) << this.n_huffs_bits[1]) - 1 + if this.transformed_history_count < args.dst.history_position() { + return base."#bad I/O position" + } + hdist_adjustment = ((this.transformed_history_count - args.dst.history_position()) & 0xFFFF_FFFF) as base.u32 + // Check up front, on each iteration, that we have enough buffer space to // both read (8 bytes) and write (266 bytes) as much as we need to. Doing // this check once (per iteration), up front, removes the need to check @@ -208,6 +214,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader hlen = length length = 0 } + hdist ~mod+= hdist_adjustment if this.history_index < hdist { return "#bad distance" } diff --git a/std/deflate/decode_huffman_slow.wuffs b/std/deflate/decode_huffman_slow.wuffs index e75a4b1b..981e2844 100644 --- a/std/deflate/decode_huffman_slow.wuffs +++ b/std/deflate/decode_huffman_slow.wuffs @@ -217,6 +217,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader) hlen = length length = 0 } + hdist ~mod+= ((this.transformed_history_count ~mod- args.dst.history_position()) & 0xFFFF_FFFF) as base.u32 if this.history_index < hdist { return "#bad distance" } diff --git a/test/c/std/gzip.c b/test/c/std/gzip.c index e5780a74..42407c65 100644 --- a/test/c/std/gzip.c +++ b/test/c/std/gzip.c @@ -216,6 +216,65 @@ test_wuffs_gzip_checksum_verify_good() { return do_test_wuffs_gzip_checksum(false, 0); } +const char* // +test_wuffs_gzip_decode_infrequent_compaction() { + CHECK_FOCUS(__func__); + + wuffs_gzip__decoder dec; + CHECK_STATUS("initialize", + wuffs_gzip__decoder__initialize( + &dec, sizeof dec, WUFFS_VERSION, + WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); + + wuffs_base__io_buffer dst = ((wuffs_base__io_buffer){ + .data = g_have_slice_u8, + }); + + // src_bytes holds the first 50 Fibonacci numbers, gzipped using Python's + // gzip module. + uint8_t src_bytes[183] = { + 0x1F, 0x8B, 0x08, 0x00, 0x07, 0x22, 0x16, 0x61, 0x02, 0xFF, 0x15, 0x8F, + 0xC1, 0x11, 0x00, 0x31, 0x08, 0x02, 0xFF, 0x54, 0x23, 0x6A, 0x44, 0xFB, + 0x6F, 0xEC, 0xB8, 0xC9, 0xCB, 0x59, 0x09, 0x6B, 0x80, 0x7E, 0x89, 0xC2, + 0xC3, 0x82, 0x85, 0x24, 0xAA, 0xF1, 0x3C, 0x1D, 0xD8, 0x8D, 0xAC, 0x42, + 0x49, 0x18, 0x06, 0x6E, 0x05, 0xBE, 0x13, 0xF2, 0x6D, 0xA3, 0xB9, 0xC4, + 0x68, 0x1E, 0x18, 0xD7, 0x03, 0x4A, 0xF4, 0x57, 0x3B, 0x4F, 0xE8, 0xA9, + 0x59, 0xE8, 0x45, 0x9A, 0x26, 0xEB, 0x0A, 0xBC, 0x71, 0x02, 0x45, 0xAD, + 0xD7, 0x1E, 0x3B, 0xF3, 0xB0, 0x95, 0xD1, 0xE1, 0xDE, 0x9E, 0x9C, 0x73, + 0xB9, 0xB6, 0xE2, 0x50, 0x2F, 0xFB, 0x69, 0xF1, 0x14, 0xB9, 0x2E, 0xBD, + 0x4C, 0xF5, 0x5F, 0xD4, 0x57, 0x61, 0x88, 0x6C, 0x9A, 0x53, 0xA8, 0x8B, + 0x5D, 0x3A, 0x3A, 0xE5, 0xC8, 0xAD, 0x35, 0xC2, 0xCA, 0xC6, 0xDE, 0x9E, + 0xF7, 0x36, 0xD8, 0x96, 0x1A, 0x9D, 0x0B, 0x6F, 0xD0, 0x66, 0xD7, 0x5D, + 0x82, 0x4C, 0x62, 0xE5, 0xF3, 0xE8, 0xFA, 0x0B, 0x8B, 0x59, 0x64, 0x6B, + 0x8A, 0xF4, 0x84, 0x3C, 0xD9, 0xFC, 0x85, 0x0A, 0xBD, 0xA1, 0x67, 0x3F, + 0x0D, 0x24, 0xAD, 0xDA, 0xD2, 0x87, 0x0F, 0x12, 0x69, 0x4A, 0xA8, 0x3B, + 0x01, 0x00, 0x00, + }; + wuffs_base__io_buffer src = + wuffs_base__ptr_u8__reader(src_bytes, sizeof src_bytes, true); + + // Decode 5 source bytes at a time. Compact every 15 source bytes. + for (size_t i = 0; i < src.data.len; i += 5) { + src.meta.wi = i; + wuffs_base__status status = + wuffs_gzip__decoder__transform_io(&dec, &dst, &src, g_work_slice_u8); + if (status.repr != wuffs_base__suspension__short_read) { + RETURN_FAIL("i=%zu: have \"%s\", want \"%s\"", i, status.repr, + wuffs_base__suspension__short_read); + } + if (i % 15 == 0) { + dst.meta.ri = dst.meta.wi; + wuffs_base__io_buffer__compact(&dst); + } + } + + src.meta.wi = src.data.len; + src.meta.closed = true; + CHECK_STATUS("final transform_io", wuffs_gzip__decoder__transform_io( + &dec, &dst, &src, g_work_slice_u8)); + return NULL; +} + const char* // test_wuffs_gzip_decode_midsummer() { CHECK_FOCUS(__func__); @@ -299,6 +358,7 @@ proc g_tests[] = { test_wuffs_gzip_checksum_verify_bad0, test_wuffs_gzip_checksum_verify_bad7, test_wuffs_gzip_checksum_verify_good, + test_wuffs_gzip_decode_infrequent_compaction, test_wuffs_gzip_decode_interface, test_wuffs_gzip_decode_midsummer, test_wuffs_gzip_decode_pi,