Commit 7d86d574 authored by Ilya Tocar's avatar Ilya Tocar Committed by Brad Fitzpatrick

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 <ilya.tocar@intel.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 9358f7fa
...@@ -10,6 +10,7 @@ package net ...@@ -10,6 +10,7 @@ package net
import ( import (
"io" "io"
"os" "os"
_ "unsafe" // For go:linkname
) )
type file struct { type file struct {
...@@ -70,14 +71,11 @@ func open(name string) (*file, error) { ...@@ -70,14 +71,11 @@ func open(name string) (*file, error) {
return &file{fd, make([]byte, 0, os.Getpagesize()), false}, nil return &file{fd, make([]byte, 0, os.Getpagesize()), false}, nil
} }
func byteIndex(s string, c byte) int { // byteIndex is strings.IndexByte. It returns the index of the
for i := 0; i < len(s); i++ { // first instance of c in s, or -1 if c is not present in s.
if s[i] == c { // strings.IndexByte is implemented in runtime/asm_$GOARCH.s
return i //go:linkname byteIndex strings.IndexByte
} func byteIndex(s string, c byte) int
}
return -1
}
// Count occurrences in s of any bytes in t. // Count occurrences in s of any bytes in t.
func countAnyByte(s string, t string) int { func countAnyByte(s string, t string) int {
...@@ -314,14 +312,9 @@ func foreachField(x []byte, fn func(field []byte) error) error { ...@@ -314,14 +312,9 @@ func foreachField(x []byte, fn func(field []byte) error) error {
// bytesIndexByte is bytes.IndexByte. It returns the index of the // bytesIndexByte is bytes.IndexByte. It returns the index of the
// first instance of c in s, or -1 if c is not present in s. // first instance of c in s, or -1 if c is not present in s.
func bytesIndexByte(s []byte, c byte) int { // bytes.IndexByte is implemented in runtime/asm_$GOARCH.s
for i, b := range s { //go:linkname bytesIndexByte bytes.IndexByte
if b == c { func bytesIndexByte(s []byte, c byte) int
return i
}
}
return -1
}
// stringsHasSuffix is strings.HasSuffix. It reports whether s ends in // stringsHasSuffix is strings.HasSuffix. It reports whether s ends in
// suffix. // suffix.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment