aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorapocelipes <seve3r@outlook.com>2024-09-04 12:02:38 +0000
committerGopher Robot <gobot@golang.org>2024-09-06 13:15:29 +0000
commit12dcbed45190fecf56ca46d82cd7439cf6015b67 (patch)
tree858f82f99898ecddfa4e6f7792aa17712e47ca48 /src
parent123594d3863b0a4b9094a569957d1bd94ebe7512 (diff)
downloadgo-12dcbed45190fecf56ca46d82cd7439cf6015b67.tar.xz
compress/flate: use built-in clear to simplify the code
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>
Diffstat (limited to 'src')
-rw-r--r--src/compress/flate/deflate.go8
-rw-r--r--src/compress/flate/deflatefast.go4
-rw-r--r--src/compress/flate/huffman_bit_writer.go16
3 files changed, 7 insertions, 21 deletions
diff --git a/src/compress/flate/deflate.go b/src/compress/flate/deflate.go
index 0e07afab7d..3d8728ead9 100644
--- a/src/compress/flate/deflate.go
+++ b/src/compress/flate/deflate.go
@@ -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
diff --git a/src/compress/flate/deflatefast.go b/src/compress/flate/deflatefast.go
index 6aa439f13d..e5554d6fb4 100644
--- a/src/compress/flate/deflatefast.go
+++ b/src/compress/flate/deflatefast.go
@@ -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
}
diff --git a/src/compress/flate/huffman_bit_writer.go b/src/compress/flate/huffman_bit_writer.go
index 005637557e..d68c77fb32 100644
--- a/src/compress/flate/huffman_bit_writer.go
+++ b/src/compress/flate/huffman_bit_writer.go
@@ -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)