]> Cypherpunks repositories - gostls13.git/commitdiff
compress/flate: use built-in clear to simplify the code
authorapocelipes <seve3r@outlook.com>
Wed, 4 Sep 2024 12:02:38 +0000 (12:02 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 6 Sep 2024 13:15:29 +0000 (13:15 +0000)
The new bootstrap toolchain allows us to use the built-in clear.

Updates #64751

Change-Id: Ic363e1059f34c46eaa4267c0b40a4ed8d5b3961b
GitHub-Last-Rev: 46ca735bfcd99a9874d7904a705970ed0cadf61c
GitHub-Pull-Request: golang/go#69253
Reviewed-on: https://go-review.googlesource.com/c/go/+/610516
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/compress/flate/deflate.go
src/compress/flate/deflatefast.go
src/compress/flate/huffman_bit_writer.go

index 0e07afab7de78b1f8a18294c12594b3562991c30..3d8728ead9c5451218faab90c0b0701eab89c045 100644 (file)
@@ -612,12 +612,8 @@ func (d *compressor) reset(w io.Writer) {
                d.bestSpeed.reset()
        default:
                d.chainHead = -1
-               for i := range d.hashHead {
-                       d.hashHead[i] = 0
-               }
-               for i := range d.hashPrev {
-                       d.hashPrev[i] = 0
-               }
+               clear(d.hashHead[:])
+               clear(d.hashPrev[:])
                d.hashOffset = 1
                d.index, d.windowEnd = 0, 0
                d.blockStart, d.byteAvailable = 0, false
index 6aa439f13d9772afe28ec0a24510b0cf4564a02e..e5554d6fb40842ca757e41960cce349d7587f483 100644 (file)
@@ -286,9 +286,7 @@ func (e *deflateFast) reset() {
 func (e *deflateFast) shiftOffsets() {
        if len(e.prev) == 0 {
                // We have no history; just clear the table.
-               for i := range e.table[:] {
-                       e.table[i] = tableEntry{}
-               }
+               clear(e.table[:])
                e.cur = maxMatchOffset + 1
                return
        }
index 005637557ebbeb9fa60f4613a6ac5fb1c5f36aa8..d68c77fb32e32a859b5a2638db32e4ef88d4feef 100644 (file)
@@ -198,9 +198,7 @@ func (w *huffmanBitWriter) writeBytes(bytes []byte) {
 //     numOffsets       The number of offsets in offsetEncoding
 //     litenc, offenc   The literal and offset encoder to use
 func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litEnc, offEnc *huffmanEncoder) {
-       for i := range w.codegenFreq {
-               w.codegenFreq[i] = 0
-       }
+       clear(w.codegenFreq[:])
        // Note that we are using codegen both as a temporary variable for holding
        // a copy of the frequencies, and as the place where we put the result.
        // This is fine because the output is always shorter than the input used
@@ -530,12 +528,8 @@ func (w *huffmanBitWriter) writeBlockDynamic(tokens []token, eof bool, input []b
 // and offsetEncoding.
 // The number of literal and offset tokens is returned.
 func (w *huffmanBitWriter) indexTokens(tokens []token) (numLiterals, numOffsets int) {
-       for i := range w.literalFreq {
-               w.literalFreq[i] = 0
-       }
-       for i := range w.offsetFreq {
-               w.offsetFreq[i] = 0
-       }
+       clear(w.literalFreq)
+       clear(w.offsetFreq)
 
        for _, t := range tokens {
                if t < matchType {
@@ -621,9 +615,7 @@ func (w *huffmanBitWriter) writeBlockHuff(eof bool, input []byte) {
        }
 
        // Clear histogram
-       for i := range w.literalFreq {
-               w.literalFreq[i] = 0
-       }
+       clear(w.literalFreq)
 
        // Add everything as literals
        histogram(input, w.literalFreq)