Skip to content

compress/flate: use built-in clear to simplify the code #69253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/compress/flate/deflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/compress/flate/deflatefast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 4 additions & 12 deletions src/compress/flate/huffman_bit_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down