diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index b31f444d..7b514022 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -2291,25 +2291,15 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast( v_hdist), v_hlen); if (v_hlen <= v_n_copied) { - v_hlen = 0; goto label_1_break; } - if (v_n_copied > 0) { - v_hlen -= v_n_copied; - v_hdist = ((v_hdist + v_n_copied) & 32767); - if (v_hdist == 0) { - if (v_hlen > 0) { - puffs_base__writer1__copy_from_slice32( - &b_wptr_dst, b_wend_dst, - ((puffs_base__slice_u8){ - .ptr = self->private_impl.f_history, .len = 32768}), - v_hlen); - } - goto label_1_break; - } - } - status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE; - PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); + v_hlen -= v_n_copied; + puffs_base__writer1__copy_from_slice32( + &b_wptr_dst, b_wend_dst, + ((puffs_base__slice_u8){.ptr = self->private_impl.f_history, + .len = 32768}), + v_hlen); + goto label_1_break; } label_1_break:; if (v_length == 0) { @@ -2326,7 +2316,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast( label_0_break:; while (v_n_bits >= 8) { v_n_bits -= 8; - PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); if (b_rptr_src == b_rstart_src) { status = PUFFS_FLATE__ERROR_INVALID_I_O_OPERATION; goto exit; diff --git a/std/flate/decode_huffman_fast.puffs b/std/flate/decode_huffman_fast.puffs index 129807cb..a8d90f8c 100644 --- a/std/flate/decode_huffman_fast.puffs +++ b/std/flate/decode_huffman_fast.puffs @@ -280,32 +280,20 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() { // start copying from. hdist = (this.history_index - hdist) & 0x7FFF - // Copy from hdist to the end of this.history. + // Copy from hdist to the end of this.history, and then + // possibly wrap around the this.history ringbuffer. + // + // The "while true { etc; break }" is a redundant version of + // "etc", but its presence minimizes the diff between + // decode_huffman_fast and decode_huffman_slow. while true { n_copied = in.dst.copy_from_slice32(s:this.history[hdist:], length:hlen) if hlen <= n_copied { - hlen = 0 break } - if n_copied > 0 { - hlen -= n_copied - hdist = (hdist ~+ n_copied) & 0x7FFF - if hdist == 0 { - // Wrap around the this.history ringbuffer. - if hlen > 0 { - in.dst.copy_from_slice32(s:this.history[:], length:hlen) - } - break - } - } - // TODO: "closed for writes" instead? - return suspension "short write" - // TODO: this "assert false" should be a compiler error. - // This might mean differentiating "return" and "raise". - // - // TODO: invalidate this-related facts because the - // suspension can change the state of this and its fields. - assert false + hlen -= n_copied + in.dst.copy_from_slice32(s:this.history[:], length:hlen) + break } if length == 0 {