1
0
mirror of https://github.com/golang/go synced 2024-11-11 17:51:49 -07:00

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: 46ca735bfc
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>
This commit is contained in:
apocelipes 2024-09-04 12:02:38 +00:00 committed by Gopher Robot
parent 123594d386
commit 12dcbed451
3 changed files with 7 additions and 21 deletions

View File

@ -612,12 +612,8 @@ func (d *compressor) reset(w io.Writer) {
d.bestSpeed.reset() d.bestSpeed.reset()
default: default:
d.chainHead = -1 d.chainHead = -1
for i := range d.hashHead { clear(d.hashHead[:])
d.hashHead[i] = 0 clear(d.hashPrev[:])
}
for i := range d.hashPrev {
d.hashPrev[i] = 0
}
d.hashOffset = 1 d.hashOffset = 1
d.index, d.windowEnd = 0, 0 d.index, d.windowEnd = 0, 0
d.blockStart, d.byteAvailable = 0, false d.blockStart, d.byteAvailable = 0, false

View File

@ -286,9 +286,7 @@ func (e *deflateFast) reset() {
func (e *deflateFast) shiftOffsets() { func (e *deflateFast) shiftOffsets() {
if len(e.prev) == 0 { if len(e.prev) == 0 {
// We have no history; just clear the table. // We have no history; just clear the table.
for i := range e.table[:] { clear(e.table[:])
e.table[i] = tableEntry{}
}
e.cur = maxMatchOffset + 1 e.cur = maxMatchOffset + 1
return return
} }

View File

@ -198,9 +198,7 @@ func (w *huffmanBitWriter) writeBytes(bytes []byte) {
// numOffsets The number of offsets in offsetEncoding // numOffsets The number of offsets in offsetEncoding
// litenc, offenc The literal and offset encoder to use // litenc, offenc The literal and offset encoder to use
func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litEnc, offEnc *huffmanEncoder) { func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litEnc, offEnc *huffmanEncoder) {
for i := range w.codegenFreq { clear(w.codegenFreq[:])
w.codegenFreq[i] = 0
}
// Note that we are using codegen both as a temporary variable for holding // 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. // 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 // 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. // and offsetEncoding.
// The number of literal and offset tokens is returned. // The number of literal and offset tokens is returned.
func (w *huffmanBitWriter) indexTokens(tokens []token) (numLiterals, numOffsets int) { func (w *huffmanBitWriter) indexTokens(tokens []token) (numLiterals, numOffsets int) {
for i := range w.literalFreq { clear(w.literalFreq)
w.literalFreq[i] = 0 clear(w.offsetFreq)
}
for i := range w.offsetFreq {
w.offsetFreq[i] = 0
}
for _, t := range tokens { for _, t := range tokens {
if t < matchType { if t < matchType {
@ -621,9 +615,7 @@ func (w *huffmanBitWriter) writeBlockHuff(eof bool, input []byte) {
} }
// Clear histogram // Clear histogram
for i := range w.literalFreq { clear(w.literalFreq)
w.literalFreq[i] = 0
}
// Add everything as literals // Add everything as literals
histogram(input, w.literalFreq) histogram(input, w.literalFreq)