From 25776a724e9c6eeb9ecf13f93b54bdcbbf07f4f3 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 26 Dec 2018 19:14:07 +1100 Subject: [PATCH] Place more vars at the top of functions --- release/c/wuffs-unsupported-snapshot.c | 16 +++++++++++++--- std/adler32/common_adler32.wuffs | 10 +++++++--- std/crc32/common_crc32.wuffs | 4 +++- std/gzip/decode_gzip.wuffs | 23 +++++++++++++++-------- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 8f31957d..5c108c1c 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -4210,6 +4210,9 @@ wuffs_adler32__hasher__update(wuffs_adler32__hasher* self, uint32_t v_s2; wuffs_base__slice_u8 v_remaining; + v_s1 = 0; + v_s2 = 0; + v_remaining = ((wuffs_base__slice_u8){}); if (!self->private_impl.f_started) { self->private_impl.f_started = true; self->private_impl.f_state = 1; @@ -4217,7 +4220,7 @@ wuffs_adler32__hasher__update(wuffs_adler32__hasher* self, v_s1 = ((self->private_impl.f_state) & 0xFFFF); v_s2 = ((self->private_impl.f_state) >> (32 - (16))); while (((uint64_t)(a_x.len)) > 0) { - v_remaining = ((wuffs_base__slice_u8){}); + v_remaining = wuffs_base__slice_u8__subslice_j(a_x, 0); if (((uint64_t)(a_x.len)) > 5552) { v_remaining = wuffs_base__slice_u8__subslice_i(a_x, 5552); a_x = wuffs_base__slice_u8__subslice_j(a_x, 5552); @@ -5049,6 +5052,7 @@ wuffs_crc32__ieee_hasher__update(wuffs_crc32__ieee_hasher* self, uint32_t v_s; + v_s = 0; v_s = (4294967295 ^ self->private_impl.f_state); { wuffs_base__slice_u8 i_slice_p = a_x; @@ -10012,6 +10016,14 @@ wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self, switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + v_c = 0; + v_flags = 0; + v_xlen = 0; + v_checksum_got = 0; + v_decoded_length_got = 0; + v_z = 0; + v_checksum_want = 0; + v_decoded_length_want = 0; { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) { @@ -10164,8 +10176,6 @@ wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self, status = wuffs_gzip__error__bad_encoding_flags; goto exit; } - v_checksum_got = 0; - v_decoded_length_got = 0; while (true) { wuffs_base__io_writer__set_mark(&a_dst, iop_a_dst); { diff --git a/std/adler32/common_adler32.wuffs b/std/adler32/common_adler32.wuffs index d786c949..e1afabe9 100644 --- a/std/adler32/common_adler32.wuffs +++ b/std/adler32/common_adler32.wuffs @@ -22,16 +22,20 @@ pub func hasher.update!(x slice base.u8) base.u32 { // The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in // RFC 1950. + var s1 base.u32 + var s2 base.u32 + var remaining slice base.u8 + if not this.started { this.started = true this.state = 1 } - var s1 base.u32 = this.state.low_bits(n:16) - var s2 base.u32 = this.state.high_bits(n:16) + s1 = this.state.low_bits(n:16) + s2 = this.state.high_bits(n:16) while args.x.length() > 0 { - var remaining slice base.u8 + remaining = args.x[:0] if args.x.length() > 5552 { remaining = args.x[5552:] args.x = args.x[:5552] diff --git a/std/crc32/common_crc32.wuffs b/std/crc32/common_crc32.wuffs index a8c9f13f..fd5f15ae 100644 --- a/std/crc32/common_crc32.wuffs +++ b/std/crc32/common_crc32.wuffs @@ -21,7 +21,9 @@ pub struct ieee_hasher?( // to signal "initializer not called"? Should the return type, in the generated // C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"? pub func ieee_hasher.update!(x slice base.u8) base.u32 { - var s base.u32 = 0xFFFFFFFF ^ this.state + var s base.u32 + + s = 0xFFFFFFFF ^ this.state // See "Multi-Byte Lookup Tables" in std/crc32/README.md for more detail on // the slicing-by-M algorithm. We use an M of 16. diff --git a/std/gzip/decode_gzip.wuffs b/std/gzip/decode_gzip.wuffs index d0550f4e..2273d1b6 100644 --- a/std/gzip/decode_gzip.wuffs +++ b/std/gzip/decode_gzip.wuffs @@ -31,8 +31,17 @@ pub func decoder.set_ignore_checksum!(ic base.bool) { } pub func decoder.decode!??(dst base.io_writer, src base.io_reader) { + var c base.u8 + var flags base.u8 + var xlen base.u16 + var checksum_got base.u32 + var decoded_length_got base.u32 + var z base.status + var checksum_want base.u32 + var decoded_length_want base.u32 + // Read the header. - var c base.u8 = args.src.read_u8!??() + c = args.src.read_u8!??() if c != 0x1F { return "?bad header" } @@ -44,13 +53,13 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) { if c != 0x08 { return "?bad compression method" } - var flags base.u8 = args.src.read_u8!??() + flags = args.src.read_u8!??() // TODO: API for returning the header's MTIME field. args.src.skip!??(n:6) // Handle FEXTRA. if (flags & 0x04) != 0 { - var xlen base.u16 = args.src.read_u16le!??() + xlen = args.src.read_u16le!??() args.src.skip!??(n:xlen as base.u32) } @@ -89,11 +98,9 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) { } // Decode and checksum the DEFLATE-encoded payload. - var checksum_got base.u32 - var decoded_length_got base.u32 while true { args.dst.set_mark!() - var z base.status =? this.flate.decode!??(dst:args.dst, src:args.src) + z =? this.flate.decode!??(dst:args.dst, src:args.src) if not this.ignore_checksum { checksum_got = this.checksum.update!(x:args.dst.since_mark()) decoded_length_got ~mod+= ((args.dst.since_mark().length() & 0xFFFFFFFF) as base.u32) @@ -103,8 +110,8 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) { } yield z } - var checksum_want base.u32 = args.src.read_u32le!??() - var decoded_length_want base.u32 = args.src.read_u32le!??() + checksum_want = args.src.read_u32le!??() + decoded_length_want = args.src.read_u32le!??() if (not this.ignore_checksum) and ((checksum_got != checksum_want) or (decoded_length_got != decoded_length_want)) { return "?bad checksum"