From bb8623b4727aaf732864d337e599ec79662e91f1 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 20 Nov 2021 20:08:54 +1100 Subject: [PATCH] Have deflate slow-Huffman use extended ringbuffer This is the same optimization as commit e65c8612 "Extend std/deflate ringbuffer to simplify copies", applied to decoder.decode_huffman_slow. --- release/c/wuffs-unsupported-snapshot.c | 23 ++++------------------- std/deflate/decode_huffman_slow.wuffs | 16 +--------------- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 5275a315..65cbc4f1 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -28152,7 +28152,7 @@ wuffs_deflate__decoder__decode_huffman_slow( v_hdist = (self->private_impl.f_history_index - v_hdist); while (true) { v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice( - &iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767))); + &iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767))); if (v_hlen <= v_n_copied) { v_hlen = 0; goto label__4__break; @@ -28168,21 +28168,6 @@ wuffs_deflate__decoder__decode_huffman_slow( WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9); } label__4__break:; - if (v_hlen > 0) { - while (true) { - v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice( - &iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767))); - if (v_hlen <= v_n_copied) { - v_hlen = 0; - goto label__5__break; - } - v_hlen -= v_n_copied; - v_hdist += v_n_copied; - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10); - } - label__5__break:; - } if (v_length == 0) { goto label__loop__continue; } @@ -28191,13 +28176,13 @@ wuffs_deflate__decoder__decode_huffman_slow( &iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1)); if (v_length <= v_n_copied) { v_length = 0; - goto label__6__break; + goto label__5__break; } v_length -= v_n_copied; status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10); } - label__6__break:; + label__5__break:; } label__loop__break:; self->private_impl.f_bits = v_bits; diff --git a/std/deflate/decode_huffman_slow.wuffs b/std/deflate/decode_huffman_slow.wuffs index 981e2844..9a455551 100644 --- a/std/deflate/decode_huffman_slow.wuffs +++ b/std/deflate/decode_huffman_slow.wuffs @@ -228,7 +228,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader) // Copy from hdist to the end of this.history. while true { n_copied = args.dst.limited_copy_u32_from_slice!( - up_to: hlen, s: this.history[hdist & 0x7FFF .. 0x8000]) + up_to: hlen, s: this.history[hdist & 0x7FFF ..]) if hlen <= n_copied { hlen = 0 break @@ -243,20 +243,6 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader) } yield? base."$short write" } endwhile - // Copy from the start of this.history, if we wrapped around. - if hlen > 0 { - while true { - n_copied = args.dst.limited_copy_u32_from_slice!( - up_to: hlen, s: this.history[hdist & 0x7FFF .. 0x8000]) - if hlen <= n_copied { - hlen = 0 - break - } - hlen -= n_copied - hdist ~mod+= n_copied - yield? base."$short write" - } endwhile - } if length == 0 { // No need to copy from args.dst.