From: Ilya Tocar Date: Thu, 15 Oct 2015 15:59:01 +0000 (+0300) Subject: net: use IndexByte implementation from runtime package X-Git-Tag: go1.6beta1~825 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7d86d5744484bd3297acb7c4a71fadd5670e5f82;p=gostls13.git 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- diff --git a/src/net/parse.go b/src/net/parse.go index c72e1c2eaf..2c686f5a9f 100644 --- a/src/net/parse.go +++ b/src/net/parse.go @@ -10,6 +10,7 @@ package net import ( "io" "os" + _ "unsafe" // For go:linkname ) type file struct { @@ -70,14 +71,11 @@ func open(name string) (*file, error) { return &file{fd, make([]byte, 0, os.Getpagesize()), false}, nil } -func byteIndex(s string, c byte) int { - for i := 0; i < len(s); i++ { - if s[i] == c { - return i - } - } - return -1 -} +// byteIndex is strings.IndexByte. It returns the index of the +// first instance of c in s, or -1 if c is not present in s. +// strings.IndexByte is implemented in runtime/asm_$GOARCH.s +//go:linkname byteIndex strings.IndexByte +func byteIndex(s string, c byte) int // Count occurrences in s of any bytes in t. func countAnyByte(s string, t string) int { @@ -314,14 +312,9 @@ func foreachField(x []byte, fn func(field []byte) error) error { // 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. -func bytesIndexByte(s []byte, c byte) int { - for i, b := range s { - if b == c { - return i - } - } - return -1 -} +// bytes.IndexByte is implemented in runtime/asm_$GOARCH.s +//go:linkname bytesIndexByte bytes.IndexByte +func bytesIndexByte(s []byte, c byte) int // stringsHasSuffix is strings.HasSuffix. It reports whether s ends in // suffix.