]> Cypherpunks repositories - gostls13.git/commitdiff
compress/bzip2,lzw: use built-in clear to simplify code
authorapocelipes <seve3r@outlook.com>
Mon, 18 Mar 2024 08:56:12 +0000 (08:56 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 18 Mar 2024 16:57:58 +0000 (16:57 +0000)
Change-Id: I16c17e322c757c8c657364065948d7cec66a8346
GitHub-Last-Rev: 9a5104fe9874dd7c604c526be3f082487f2aaf01
GitHub-Pull-Request: golang/go#66377
Reviewed-on: https://go-review.googlesource.com/c/go/+/572199
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/compress/bzip2/bzip2.go
src/compress/lzw/reader_test.go

index 8f88e384f2e901bb99d32597e8ddb5c78190e6a9..73e201b80e2b38b0ee0f4e9ce52cc0b4d6615e80 100644 (file)
@@ -355,9 +355,7 @@ func (bz2 *reader) readBlock() (err error) {
        repeatPower := 0
 
        // The `C' array (used by the inverse BWT) needs to be zero initialized.
-       for i := range bz2.c {
-               bz2.c[i] = 0
-       }
+       clear(bz2.c[:])
 
        decoded := 0 // counts the number of symbols decoded by the current tree.
        for {
index 9a2a4773024a96bd307dc06109c52dae2fd45927..0b1182dbf772235ac30ec576671e4bbafd8e692f 100644 (file)
@@ -170,9 +170,7 @@ func TestReaderReset(t *testing.T) {
 type devZero struct{}
 
 func (devZero) Read(p []byte) (int, error) {
-       for i := range p {
-               p[i] = 0
-       }
+       clear(p)
        return len(p), nil
 }