]> Cypherpunks repositories - gostls13.git/commitdiff
all: omit unnecessary 0 in slice expression
authornlwkobe30 <nlwkobe30@gmail.com>
Fri, 30 Aug 2024 19:05:07 +0000 (19:05 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 3 Sep 2024 20:55:15 +0000 (20:55 +0000)
All changes are related to the code, except for the comments in src/regexp/syntax/parse.go and src/slices/slices.go.

Change-Id: I73c5d3c54099749b62210aa7f3182c5eb84bb6a6
GitHub-Last-Rev: 794aa9b0539811d00e1cd42be1e8d9fe9afe0281
GitHub-Pull-Request: golang/go#69170
Reviewed-on: https://go-review.googlesource.com/c/go/+/609678
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>

19 files changed:
src/bufio/bufio_test.go
src/bytes/buffer_test.go
src/bytes/bytes.go
src/cmd/internal/notsha256/sha256_test.go
src/crypto/cipher/ctr_aes_test.go
src/crypto/internal/cryptotest/aead.go
src/crypto/internal/cryptotest/hash.go
src/crypto/md5/md5_test.go
src/crypto/sha1/sha1_test.go
src/crypto/sha256/sha256_test.go
src/crypto/subtle/constant_time_test.go
src/go/internal/gccgoimporter/parser.go
src/internal/stringslite/strings.go
src/math/big/natdiv.go
src/net/http/client_test.go
src/regexp/syntax/parse.go
src/slices/slices.go
src/time/format.go
src/unicode/utf8/utf8_test.go

index a8c1e503978847c3473bf964349959397b0cf552..c68184269288dc9d0a7b34d9f03bfdfa8ac732a2 100644 (file)
@@ -636,7 +636,7 @@ func TestWriter(t *testing.T) {
                        for l := 0; l < len(written); l++ {
                                if written[l] != data[l] {
                                        t.Errorf("wrong bytes written")
-                                       t.Errorf("want=%q", data[0:len(written)])
+                                       t.Errorf("want=%q", data[:len(written)])
                                        t.Errorf("have=%q", written)
                                }
                        }
index 3c964fc6b990bbbb86d0c638291053873a9f3458..97fca5a9d136f99517a7aca93511bfb1aa8ad685 100644 (file)
@@ -213,7 +213,7 @@ func TestLargeByteWrites(t *testing.T) {
 func TestLargeStringReads(t *testing.T) {
        var buf Buffer
        for i := 3; i < 30; i += 3 {
-               s := fillString(t, "TestLargeReads (1)", &buf, "", 5, testString[0:len(testString)/i])
+               s := fillString(t, "TestLargeReads (1)", &buf, "", 5, testString[:len(testString)/i])
                empty(t, "TestLargeReads (2)", &buf, s, make([]byte, len(testString)))
        }
        check(t, "TestLargeStringReads (3)", &buf, "")
@@ -222,7 +222,7 @@ func TestLargeStringReads(t *testing.T) {
 func TestLargeByteReads(t *testing.T) {
        var buf Buffer
        for i := 3; i < 30; i += 3 {
-               s := fillBytes(t, "TestLargeReads (1)", &buf, "", 5, testBytes[0:len(testBytes)/i])
+               s := fillBytes(t, "TestLargeReads (1)", &buf, "", 5, testBytes[:len(testBytes)/i])
                empty(t, "TestLargeReads (2)", &buf, s, make([]byte, len(testString)))
        }
        check(t, "TestLargeByteReads (3)", &buf, "")
@@ -274,7 +274,7 @@ func TestNil(t *testing.T) {
 func TestReadFrom(t *testing.T) {
        var buf Buffer
        for i := 3; i < 30; i += 3 {
-               s := fillBytes(t, "TestReadFrom (1)", &buf, "", 5, testBytes[0:len(testBytes)/i])
+               s := fillBytes(t, "TestReadFrom (1)", &buf, "", 5, testBytes[:len(testBytes)/i])
                var b Buffer
                b.ReadFrom(&buf)
                empty(t, "TestReadFrom (2)", &b, s, make([]byte, len(testString)))
@@ -337,7 +337,7 @@ func TestReadFromNegativeReader(t *testing.T) {
 func TestWriteTo(t *testing.T) {
        var buf Buffer
        for i := 3; i < 30; i += 3 {
-               s := fillBytes(t, "TestWriteTo (1)", &buf, "", 5, testBytes[0:len(testBytes)/i])
+               s := fillBytes(t, "TestWriteTo (1)", &buf, "", 5, testBytes[:len(testBytes)/i])
                var b Buffer
                buf.WriteTo(&b)
                empty(t, "TestWriteTo (2)", &b, s, make([]byte, len(testString)))
index bdb036689733e6959a29068cbc255f44e54cf6fb..4a2c9eac574b60b6dd5d5303748e1a41924078b0 100644 (file)
@@ -592,7 +592,7 @@ func Join(s [][]byte, sep []byte) []byte {
 
 // HasPrefix reports whether the byte slice s begins with prefix.
 func HasPrefix(s, prefix []byte) bool {
-       return len(s) >= len(prefix) && Equal(s[0:len(prefix)], prefix)
+       return len(s) >= len(prefix) && Equal(s[:len(prefix)], prefix)
 }
 
 // HasSuffix reports whether the byte slice s ends with suffix.
index fa38e565068f3bd84aea576438a4b8b7e0a6a09b..771d572efade29e76aa685ddedf4da6801de28ee 100644 (file)
@@ -86,7 +86,7 @@ func TestGolden(t *testing.T) {
                        if j < 2 {
                                io.WriteString(c, g.in)
                        } else {
-                               io.WriteString(c, g.in[0:len(g.in)/2])
+                               io.WriteString(c, g.in[:len(g.in)/2])
                                c.Sum(nil)
                                io.WriteString(c, g.in[len(g.in)/2:])
                        }
index d019ae0d022eb803e6a00ca74e23bad5b973ea58..c82a8757ab3f8767b7a6228f91b00608fb0e3f10 100644 (file)
@@ -80,7 +80,7 @@ func TestCTR_AES(t *testing.T) {
                        ctr := cipher.NewCTR(c, tt.iv)
                        encrypted := make([]byte, len(in))
                        ctr.XORKeyStream(encrypted, in)
-                       if out := tt.out[0:len(in)]; !bytes.Equal(out, encrypted) {
+                       if out := tt.out[:len(in)]; !bytes.Equal(out, encrypted) {
                                t.Errorf("%s/%d: CTR\ninpt %x\nhave %x\nwant %x", test, len(in), in, encrypted, out)
                        }
                }
@@ -90,7 +90,7 @@ func TestCTR_AES(t *testing.T) {
                        ctr := cipher.NewCTR(c, tt.iv)
                        plain := make([]byte, len(in))
                        ctr.XORKeyStream(plain, in)
-                       if out := tt.in[0:len(in)]; !bytes.Equal(out, plain) {
+                       if out := tt.in[:len(in)]; !bytes.Equal(out, plain) {
                                t.Errorf("%s/%d: CTRReader\nhave %x\nwant %x", test, len(out), plain, out)
                        }
                }
index e17cdf8cb8628254539dea5bab3713dd061a23a4..a6107e541930d11c3e856c3b1d2f7c049feb6c31 100644 (file)
@@ -204,8 +204,8 @@ func TestAEAD(t *testing.T, mAEAD MakeAEAD) {
                                                        out := sealMsg(t, aead, prefix, nonce, plaintext, addData)
 
                                                        // Check that Seal didn't alter the prefix
-                                                       if !bytes.Equal(out[0:len(prefix)], prefix) {
-                                                               t.Errorf("Seal alters dst instead of appending; got %s, want %s", truncateHex(out[0:len(prefix)]), truncateHex(prefix))
+                                                       if !bytes.Equal(out[:len(prefix)], prefix) {
+                                                               t.Errorf("Seal alters dst instead of appending; got %s, want %s", truncateHex(out[:len(prefix)]), truncateHex(prefix))
                                                        }
 
                                                        ciphertext := out[len(prefix):]
@@ -237,8 +237,8 @@ func TestAEAD(t *testing.T, mAEAD MakeAEAD) {
                                                        out := openWithoutError(t, aead, prefix, nonce, ciphertext, addData)
 
                                                        // Check that Open didn't alter the prefix
-                                                       if !bytes.Equal(out[0:len(prefix)], prefix) {
-                                                               t.Errorf("Open alters dst instead of appending; got %s, want %s", truncateHex(out[0:len(prefix)]), truncateHex(prefix))
+                                                       if !bytes.Equal(out[:len(prefix)], prefix) {
+                                                               t.Errorf("Open alters dst instead of appending; got %s, want %s", truncateHex(out[:len(prefix)]), truncateHex(prefix))
                                                        }
 
                                                        after := out[len(prefix):]
index a950dcb282140d42ad1e8ab5993b5757cf48f18b..f03623dfa268dd260e5a36d5efb6399ca8635121 100644 (file)
@@ -39,8 +39,8 @@ func TestHash(t *testing.T, mh MakeHash) {
                        sum := getSum(t, h, prefix) // Append new digest to prefix
 
                        // Check that Sum didn't alter the prefix
-                       if !bytes.Equal(sum[0:len(prefix)], prefix) {
-                               t.Errorf("Sum alters passed buffer instead of appending; got %x, want %x", sum[0:len(prefix)], prefix)
+                       if !bytes.Equal(sum[:len(prefix)], prefix) {
+                               t.Errorf("Sum alters passed buffer instead of appending; got %x, want %x", sum[:len(prefix)], prefix)
                        }
 
                        // Check that the appended sum wasn't affected by the prefix
index c445b10832f78392a2aac72e72a2ada8d94f9f8c..6a8258a67e860c5dbe25b6df23b6b704bf159419 100644 (file)
@@ -69,7 +69,7 @@ func TestGolden(t *testing.T) {
                        if j < 2 {
                                io.WriteString(c, g.in)
                        } else if j == 2 {
-                               io.WriteString(c, g.in[0:len(g.in)/2])
+                               io.WriteString(c, g.in[:len(g.in)/2])
                                c.Sum(nil)
                                io.WriteString(c, g.in[len(g.in)/2:])
                        } else if j > 2 {
index 32b01d4dee362f57c2d3a33ac131619c73e158d8..d03892c57d4e611db50f1685bbdec03eebe39708 100644 (file)
@@ -74,7 +74,7 @@ func TestGolden(t *testing.T) {
                                io.WriteString(c, g.in)
                                sum = c.Sum(nil)
                        case 2:
-                               io.WriteString(c, g.in[0:len(g.in)/2])
+                               io.WriteString(c, g.in[:len(g.in)/2])
                                c.Sum(nil)
                                io.WriteString(c, g.in[len(g.in)/2:])
                                sum = c.Sum(nil)
@@ -82,7 +82,7 @@ func TestGolden(t *testing.T) {
                                if boring.Enabled {
                                        continue
                                }
-                               io.WriteString(c, g.in[0:len(g.in)/2])
+                               io.WriteString(c, g.in[:len(g.in)/2])
                                c.(*digest).ConstantTimeSum(nil)
                                io.WriteString(c, g.in[len(g.in)/2:])
                                sum = c.(*digest).ConstantTimeSum(nil)
index 92268f32da996b0078f0d06f85515d6d1883a36b..3237c6a73e6a1ed8ce44eaa27a302c00925bbf1d 100644 (file)
@@ -104,7 +104,7 @@ func TestGolden(t *testing.T) {
                        if j < 2 {
                                io.WriteString(c, g.in)
                        } else {
-                               io.WriteString(c, g.in[0:len(g.in)/2])
+                               io.WriteString(c, g.in[:len(g.in)/2])
                                c.Sum(nil)
                                io.WriteString(c, g.in[len(g.in)/2:])
                        }
@@ -126,7 +126,7 @@ func TestGolden(t *testing.T) {
                        if j < 2 {
                                io.WriteString(c, g.in)
                        } else {
-                               io.WriteString(c, g.in[0:len(g.in)/2])
+                               io.WriteString(c, g.in[:len(g.in)/2])
                                c.Sum(nil)
                                io.WriteString(c, g.in[len(g.in)/2:])
                        }
index 033301a6e4a87936d29bdb086607a97283a4eb0e..c2ccd28ad70f5b8b4af665732770e6a4eb86446c 100644 (file)
@@ -78,9 +78,9 @@ func TestConstantTimeEq(t *testing.T) {
 
 func makeCopy(v int, x, y []byte) []byte {
        if len(x) > len(y) {
-               x = x[0:len(y)]
+               x = x[:len(y)]
        } else {
-               y = y[0:len(x)]
+               y = y[:len(x)]
        }
        if v == 1 {
                copy(x, y)
@@ -90,9 +90,9 @@ func makeCopy(v int, x, y []byte) []byte {
 
 func constantTimeCopyWrapper(v int, x, y []byte) []byte {
        if len(x) > len(y) {
-               x = x[0:len(y)]
+               x = x[:len(y)]
        } else {
-               y = y[0:len(x)]
+               y = y[:len(x)]
        }
        v &= 1
        ConstantTimeCopy(v, x, y)
index e8ee74783b9e96f5c23623d9dfe9e1c247b450f6..a2c1033991a1a3a08480c70408a4ae7f5ba89996 100644 (file)
@@ -176,7 +176,7 @@ func (p *parser) parseQualifiedNameStr(unquotedName string) (pkgpath, name strin
                name = parts[0]
        default:
                // qualified name, which may contain periods
-               pkgpath = strings.Join(parts[0:len(parts)-1], ".")
+               pkgpath = strings.Join(parts[:len(parts)-1], ".")
                name = parts[len(parts)-1]
        }
 
index 4114b86130006648953105967cd4691b04a50a76..3a09e08cf4f7bd360e6e8b7435a655c83332f53c 100644 (file)
@@ -14,7 +14,7 @@ import (
 )
 
 func HasPrefix(s, prefix string) bool {
-       return len(s) >= len(prefix) && s[0:len(prefix)] == prefix
+       return len(s) >= len(prefix) && s[:len(prefix)] == prefix
 }
 
 func HasSuffix(s, suffix string) bool {
index b55f9990cd5975cc220c4ac0b04c09cea7c41a26..96a41c0ace0d96f49da8128d4e64d8dae15142d3 100644 (file)
@@ -602,7 +602,7 @@ func (z nat) divLarge(u, uIn, vIn nat) (q, r nat) {
        v := *vp
        shlVU(v, vIn, shift)
        u = u.make(len(uIn) + 1)
-       u[len(uIn)] = shlVU(u[0:len(uIn)], uIn, shift)
+       u[len(uIn)] = shlVU(u[:len(uIn)], uIn, shift)
 
        // The caller should not pass aliased z and u, since those are
        // the two different outputs, but correct just in case.
@@ -884,7 +884,7 @@ func (z nat) divRecursiveStep(u, v nat, depth int, tmp *nat, temps []*nat) {
        if qhatv.cmp(u.norm()) > 0 {
                panic("impossible")
        }
-       c := subVV(u[0:len(qhatv)], u[0:len(qhatv)], qhatv)
+       c := subVV(u[:len(qhatv)], u[:len(qhatv)], qhatv)
        if c > 0 {
                c = subVW(u[len(qhatv):], u[len(qhatv):], c)
        }
index 1faa1516479e75d9c04c59406e3c20f6f18bd04a..04e2e32cf07777dfb862f07f0139c33de63dacee 100644 (file)
@@ -751,7 +751,7 @@ func testStreamingGet(t *testing.T, mode testMode) {
        var buf [10]byte
        for _, str := range []string{"i", "am", "also", "known", "as", "comet"} {
                say <- str
-               n, err := io.ReadFull(res.Body, buf[0:len(str)])
+               n, err := io.ReadFull(res.Body, buf[:len(str)])
                if err != nil {
                        t.Fatalf("ReadFull on %q: %v", str, err)
                }
index 26242902f1eb26e92224df8b1d8fc250367eb143..ed239dafdf34710d5be12dcfd8d401212bf6d8c3 100644 (file)
@@ -621,7 +621,7 @@ func (p *parser) factor(sub []*Regexp) []*Regexp {
                }
 
                // Found end of a run with common leading literal string:
-               // sub[start:i] all begin with str[0:len(str)], but sub[i]
+               // sub[start:i] all begin with str[:len(str)], but sub[i]
                // does not even begin with str[0].
                //
                // Factor out common string and append factored expression to out.
index b53419f84b511be8d73da842d20b09ef5b634896..25c124d29154001f54d01cc0011831526e681f54 100644 (file)
@@ -434,7 +434,7 @@ func rotateRight[E any](s []E, r int) {
        rotateLeft(s, len(s)-r)
 }
 
-// overlaps reports whether the memory ranges a[0:len(a)] and b[0:len(b)] overlap.
+// overlaps reports whether the memory ranges a[:len(a)] and b[:len(b)] overlap.
 func overlaps[E any](a, b []E) bool {
        if len(a) == 0 || len(b) == 0 {
                return false
index c8cb9c65bc6716b2c034e917b888152d210be1b4..cab78f73a06fc8eb644c596061e875f17e2ad38c 100644 (file)
@@ -405,7 +405,7 @@ func match(s1, s2 string) bool {
 
 func lookup(tab []string, val string) (int, string, error) {
        for i, v := range tab {
-               if len(val) >= len(v) && match(val[0:len(v)], v) {
+               if len(val) >= len(v) && match(val[:len(v)], v) {
                        return i, val[len(v):], nil
                }
        }
index fa23419b3649b7f91a731eee4d11ce2b9207e5c9..2adec9754154405e932d596631b01c3a484afc4c 100644 (file)
@@ -170,7 +170,7 @@ func TestDecodeRune(t *testing.T) {
                }
                r, size = DecodeRune(b[0 : len(b)-1])
                if r != RuneError || size != wantsize {
-                       t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", b[0:len(b)-1], r, size, RuneError, wantsize)
+                       t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", b[:len(b)-1], r, size, RuneError, wantsize)
                }
                s = m.str[0 : len(m.str)-1]
                r, size = DecodeRuneInString(s)