Skip to content

Commit 6b2acbf

Browse files
apriil15pull[bot]
authored andcommitted
all: omit unnecessary 0 in slice expression
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: 794aa9b GitHub-Pull-Request: #69170 Reviewed-on: https://go-review.googlesource.com/c/go/+/609678 Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 2c66ba4 commit 6b2acbf

File tree

19 files changed

+33
-33
lines changed

19 files changed

+33
-33
lines changed

src/bufio/bufio_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ func TestWriter(t *testing.T) {
636636
for l := 0; l < len(written); l++ {
637637
if written[l] != data[l] {
638638
t.Errorf("wrong bytes written")
639-
t.Errorf("want=%q", data[0:len(written)])
639+
t.Errorf("want=%q", data[:len(written)])
640640
t.Errorf("have=%q", written)
641641
}
642642
}

src/bytes/buffer_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func TestLargeByteWrites(t *testing.T) {
213213
func TestLargeStringReads(t *testing.T) {
214214
var buf Buffer
215215
for i := 3; i < 30; i += 3 {
216-
s := fillString(t, "TestLargeReads (1)", &buf, "", 5, testString[0:len(testString)/i])
216+
s := fillString(t, "TestLargeReads (1)", &buf, "", 5, testString[:len(testString)/i])
217217
empty(t, "TestLargeReads (2)", &buf, s, make([]byte, len(testString)))
218218
}
219219
check(t, "TestLargeStringReads (3)", &buf, "")
@@ -222,7 +222,7 @@ func TestLargeStringReads(t *testing.T) {
222222
func TestLargeByteReads(t *testing.T) {
223223
var buf Buffer
224224
for i := 3; i < 30; i += 3 {
225-
s := fillBytes(t, "TestLargeReads (1)", &buf, "", 5, testBytes[0:len(testBytes)/i])
225+
s := fillBytes(t, "TestLargeReads (1)", &buf, "", 5, testBytes[:len(testBytes)/i])
226226
empty(t, "TestLargeReads (2)", &buf, s, make([]byte, len(testString)))
227227
}
228228
check(t, "TestLargeByteReads (3)", &buf, "")
@@ -274,7 +274,7 @@ func TestNil(t *testing.T) {
274274
func TestReadFrom(t *testing.T) {
275275
var buf Buffer
276276
for i := 3; i < 30; i += 3 {
277-
s := fillBytes(t, "TestReadFrom (1)", &buf, "", 5, testBytes[0:len(testBytes)/i])
277+
s := fillBytes(t, "TestReadFrom (1)", &buf, "", 5, testBytes[:len(testBytes)/i])
278278
var b Buffer
279279
b.ReadFrom(&buf)
280280
empty(t, "TestReadFrom (2)", &b, s, make([]byte, len(testString)))
@@ -337,7 +337,7 @@ func TestReadFromNegativeReader(t *testing.T) {
337337
func TestWriteTo(t *testing.T) {
338338
var buf Buffer
339339
for i := 3; i < 30; i += 3 {
340-
s := fillBytes(t, "TestWriteTo (1)", &buf, "", 5, testBytes[0:len(testBytes)/i])
340+
s := fillBytes(t, "TestWriteTo (1)", &buf, "", 5, testBytes[:len(testBytes)/i])
341341
var b Buffer
342342
buf.WriteTo(&b)
343343
empty(t, "TestWriteTo (2)", &b, s, make([]byte, len(testString)))

src/bytes/bytes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ func Join(s [][]byte, sep []byte) []byte {
592592

593593
// HasPrefix reports whether the byte slice s begins with prefix.
594594
func HasPrefix(s, prefix []byte) bool {
595-
return len(s) >= len(prefix) && Equal(s[0:len(prefix)], prefix)
595+
return len(s) >= len(prefix) && Equal(s[:len(prefix)], prefix)
596596
}
597597

598598
// HasSuffix reports whether the byte slice s ends with suffix.

src/cmd/internal/notsha256/sha256_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestGolden(t *testing.T) {
8686
if j < 2 {
8787
io.WriteString(c, g.in)
8888
} else {
89-
io.WriteString(c, g.in[0:len(g.in)/2])
89+
io.WriteString(c, g.in[:len(g.in)/2])
9090
c.Sum(nil)
9191
io.WriteString(c, g.in[len(g.in)/2:])
9292
}

src/crypto/cipher/ctr_aes_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestCTR_AES(t *testing.T) {
8080
ctr := cipher.NewCTR(c, tt.iv)
8181
encrypted := make([]byte, len(in))
8282
ctr.XORKeyStream(encrypted, in)
83-
if out := tt.out[0:len(in)]; !bytes.Equal(out, encrypted) {
83+
if out := tt.out[:len(in)]; !bytes.Equal(out, encrypted) {
8484
t.Errorf("%s/%d: CTR\ninpt %x\nhave %x\nwant %x", test, len(in), in, encrypted, out)
8585
}
8686
}
@@ -90,7 +90,7 @@ func TestCTR_AES(t *testing.T) {
9090
ctr := cipher.NewCTR(c, tt.iv)
9191
plain := make([]byte, len(in))
9292
ctr.XORKeyStream(plain, in)
93-
if out := tt.in[0:len(in)]; !bytes.Equal(out, plain) {
93+
if out := tt.in[:len(in)]; !bytes.Equal(out, plain) {
9494
t.Errorf("%s/%d: CTRReader\nhave %x\nwant %x", test, len(out), plain, out)
9595
}
9696
}

src/crypto/internal/cryptotest/aead.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ func TestAEAD(t *testing.T, mAEAD MakeAEAD) {
204204
out := sealMsg(t, aead, prefix, nonce, plaintext, addData)
205205

206206
// Check that Seal didn't alter the prefix
207-
if !bytes.Equal(out[0:len(prefix)], prefix) {
208-
t.Errorf("Seal alters dst instead of appending; got %s, want %s", truncateHex(out[0:len(prefix)]), truncateHex(prefix))
207+
if !bytes.Equal(out[:len(prefix)], prefix) {
208+
t.Errorf("Seal alters dst instead of appending; got %s, want %s", truncateHex(out[:len(prefix)]), truncateHex(prefix))
209209
}
210210

211211
ciphertext := out[len(prefix):]
@@ -237,8 +237,8 @@ func TestAEAD(t *testing.T, mAEAD MakeAEAD) {
237237
out := openWithoutError(t, aead, prefix, nonce, ciphertext, addData)
238238

239239
// Check that Open didn't alter the prefix
240-
if !bytes.Equal(out[0:len(prefix)], prefix) {
241-
t.Errorf("Open alters dst instead of appending; got %s, want %s", truncateHex(out[0:len(prefix)]), truncateHex(prefix))
240+
if !bytes.Equal(out[:len(prefix)], prefix) {
241+
t.Errorf("Open alters dst instead of appending; got %s, want %s", truncateHex(out[:len(prefix)]), truncateHex(prefix))
242242
}
243243

244244
after := out[len(prefix):]

src/crypto/internal/cryptotest/hash.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func TestHash(t *testing.T, mh MakeHash) {
3939
sum := getSum(t, h, prefix) // Append new digest to prefix
4040

4141
// Check that Sum didn't alter the prefix
42-
if !bytes.Equal(sum[0:len(prefix)], prefix) {
43-
t.Errorf("Sum alters passed buffer instead of appending; got %x, want %x", sum[0:len(prefix)], prefix)
42+
if !bytes.Equal(sum[:len(prefix)], prefix) {
43+
t.Errorf("Sum alters passed buffer instead of appending; got %x, want %x", sum[:len(prefix)], prefix)
4444
}
4545

4646
// Check that the appended sum wasn't affected by the prefix

src/crypto/md5/md5_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestGolden(t *testing.T) {
6969
if j < 2 {
7070
io.WriteString(c, g.in)
7171
} else if j == 2 {
72-
io.WriteString(c, g.in[0:len(g.in)/2])
72+
io.WriteString(c, g.in[:len(g.in)/2])
7373
c.Sum(nil)
7474
io.WriteString(c, g.in[len(g.in)/2:])
7575
} else if j > 2 {

src/crypto/sha1/sha1_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ func TestGolden(t *testing.T) {
7474
io.WriteString(c, g.in)
7575
sum = c.Sum(nil)
7676
case 2:
77-
io.WriteString(c, g.in[0:len(g.in)/2])
77+
io.WriteString(c, g.in[:len(g.in)/2])
7878
c.Sum(nil)
7979
io.WriteString(c, g.in[len(g.in)/2:])
8080
sum = c.Sum(nil)
8181
case 3:
8282
if boring.Enabled {
8383
continue
8484
}
85-
io.WriteString(c, g.in[0:len(g.in)/2])
85+
io.WriteString(c, g.in[:len(g.in)/2])
8686
c.(*digest).ConstantTimeSum(nil)
8787
io.WriteString(c, g.in[len(g.in)/2:])
8888
sum = c.(*digest).ConstantTimeSum(nil)

src/crypto/sha256/sha256_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestGolden(t *testing.T) {
104104
if j < 2 {
105105
io.WriteString(c, g.in)
106106
} else {
107-
io.WriteString(c, g.in[0:len(g.in)/2])
107+
io.WriteString(c, g.in[:len(g.in)/2])
108108
c.Sum(nil)
109109
io.WriteString(c, g.in[len(g.in)/2:])
110110
}
@@ -126,7 +126,7 @@ func TestGolden(t *testing.T) {
126126
if j < 2 {
127127
io.WriteString(c, g.in)
128128
} else {
129-
io.WriteString(c, g.in[0:len(g.in)/2])
129+
io.WriteString(c, g.in[:len(g.in)/2])
130130
c.Sum(nil)
131131
io.WriteString(c, g.in[len(g.in)/2:])
132132
}

src/crypto/subtle/constant_time_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func TestConstantTimeEq(t *testing.T) {
7878

7979
func makeCopy(v int, x, y []byte) []byte {
8080
if len(x) > len(y) {
81-
x = x[0:len(y)]
81+
x = x[:len(y)]
8282
} else {
83-
y = y[0:len(x)]
83+
y = y[:len(x)]
8484
}
8585
if v == 1 {
8686
copy(x, y)
@@ -90,9 +90,9 @@ func makeCopy(v int, x, y []byte) []byte {
9090

9191
func constantTimeCopyWrapper(v int, x, y []byte) []byte {
9292
if len(x) > len(y) {
93-
x = x[0:len(y)]
93+
x = x[:len(y)]
9494
} else {
95-
y = y[0:len(x)]
95+
y = y[:len(x)]
9696
}
9797
v &= 1
9898
ConstantTimeCopy(v, x, y)

src/go/internal/gccgoimporter/parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (p *parser) parseQualifiedNameStr(unquotedName string) (pkgpath, name strin
176176
name = parts[0]
177177
default:
178178
// qualified name, which may contain periods
179-
pkgpath = strings.Join(parts[0:len(parts)-1], ".")
179+
pkgpath = strings.Join(parts[:len(parts)-1], ".")
180180
name = parts[len(parts)-1]
181181
}
182182

src/internal/stringslite/strings.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func HasPrefix(s, prefix string) bool {
17-
return len(s) >= len(prefix) && s[0:len(prefix)] == prefix
17+
return len(s) >= len(prefix) && s[:len(prefix)] == prefix
1818
}
1919

2020
func HasSuffix(s, suffix string) bool {

src/math/big/natdiv.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ func (z nat) divLarge(u, uIn, vIn nat) (q, r nat) {
602602
v := *vp
603603
shlVU(v, vIn, shift)
604604
u = u.make(len(uIn) + 1)
605-
u[len(uIn)] = shlVU(u[0:len(uIn)], uIn, shift)
605+
u[len(uIn)] = shlVU(u[:len(uIn)], uIn, shift)
606606

607607
// The caller should not pass aliased z and u, since those are
608608
// 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) {
884884
if qhatv.cmp(u.norm()) > 0 {
885885
panic("impossible")
886886
}
887-
c := subVV(u[0:len(qhatv)], u[0:len(qhatv)], qhatv)
887+
c := subVV(u[:len(qhatv)], u[:len(qhatv)], qhatv)
888888
if c > 0 {
889889
c = subVW(u[len(qhatv):], u[len(qhatv):], c)
890890
}

src/net/http/client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func testStreamingGet(t *testing.T, mode testMode) {
751751
var buf [10]byte
752752
for _, str := range []string{"i", "am", "also", "known", "as", "comet"} {
753753
say <- str
754-
n, err := io.ReadFull(res.Body, buf[0:len(str)])
754+
n, err := io.ReadFull(res.Body, buf[:len(str)])
755755
if err != nil {
756756
t.Fatalf("ReadFull on %q: %v", str, err)
757757
}

src/regexp/syntax/parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func (p *parser) factor(sub []*Regexp) []*Regexp {
621621
}
622622

623623
// Found end of a run with common leading literal string:
624-
// sub[start:i] all begin with str[0:len(str)], but sub[i]
624+
// sub[start:i] all begin with str[:len(str)], but sub[i]
625625
// does not even begin with str[0].
626626
//
627627
// Factor out common string and append factored expression to out.

src/slices/slices.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ func rotateRight[E any](s []E, r int) {
434434
rotateLeft(s, len(s)-r)
435435
}
436436

437-
// overlaps reports whether the memory ranges a[0:len(a)] and b[0:len(b)] overlap.
437+
// overlaps reports whether the memory ranges a[:len(a)] and b[:len(b)] overlap.
438438
func overlaps[E any](a, b []E) bool {
439439
if len(a) == 0 || len(b) == 0 {
440440
return false

src/time/format.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func match(s1, s2 string) bool {
405405

406406
func lookup(tab []string, val string) (int, string, error) {
407407
for i, v := range tab {
408-
if len(val) >= len(v) && match(val[0:len(v)], v) {
408+
if len(val) >= len(v) && match(val[:len(v)], v) {
409409
return i, val[len(v):], nil
410410
}
411411
}

src/unicode/utf8/utf8_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestDecodeRune(t *testing.T) {
170170
}
171171
r, size = DecodeRune(b[0 : len(b)-1])
172172
if r != RuneError || size != wantsize {
173-
t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", b[0:len(b)-1], r, size, RuneError, wantsize)
173+
t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", b[:len(b)-1], r, size, RuneError, wantsize)
174174
}
175175
s = m.str[0 : len(m.str)-1]
176176
r, size = DecodeRuneInString(s)

0 commit comments

Comments
 (0)