Skip to content

Commit 7d86d57

Browse files
TocarIPbradfitz
authored andcommitted
net: use IndexByte implementation from runtime package
In net/parse.go we reimplement bytes.IndexByte and strings.IndexByte, However those are implemented in runtime/$GOARCH_asm.s. Using versions from runtime should provide performance advantage, and keep the same code together. Change-Id: I6212184bdf6aa1f2c03ce26d4b63f5b379d8ed0c Reviewed-on: https://go-review.googlesource.com/15953 Run-TryBot: Ilya Tocar <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 9358f7f commit 7d86d57

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/net/parse.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package net
1010
import (
1111
"io"
1212
"os"
13+
_ "unsafe" // For go:linkname
1314
)
1415

1516
type file struct {
@@ -70,14 +71,11 @@ func open(name string) (*file, error) {
7071
return &file{fd, make([]byte, 0, os.Getpagesize()), false}, nil
7172
}
7273

73-
func byteIndex(s string, c byte) int {
74-
for i := 0; i < len(s); i++ {
75-
if s[i] == c {
76-
return i
77-
}
78-
}
79-
return -1
80-
}
74+
// byteIndex is strings.IndexByte. It returns the index of the
75+
// first instance of c in s, or -1 if c is not present in s.
76+
// strings.IndexByte is implemented in runtime/asm_$GOARCH.s
77+
//go:linkname byteIndex strings.IndexByte
78+
func byteIndex(s string, c byte) int
8179

8280
// Count occurrences in s of any bytes in t.
8381
func countAnyByte(s string, t string) int {
@@ -314,14 +312,9 @@ func foreachField(x []byte, fn func(field []byte) error) error {
314312

315313
// bytesIndexByte is bytes.IndexByte. It returns the index of the
316314
// first instance of c in s, or -1 if c is not present in s.
317-
func bytesIndexByte(s []byte, c byte) int {
318-
for i, b := range s {
319-
if b == c {
320-
return i
321-
}
322-
}
323-
return -1
324-
}
315+
// bytes.IndexByte is implemented in runtime/asm_$GOARCH.s
316+
//go:linkname bytesIndexByte bytes.IndexByte
317+
func bytesIndexByte(s []byte, c byte) int
325318

326319
// stringsHasSuffix is strings.HasSuffix. It reports whether s ends in
327320
// suffix.

0 commit comments

Comments
 (0)