Commit d153df8e authored by Marvin Stenger's avatar Marvin Stenger Committed by Ian Lance Taylor

all: revert "all: prefer strings.LastIndexByte over strings.LastIndex"

This reverts https://golang.org/cl/66372.

Updates #22148

Change-Id: I3e94af3dfc11a2883bf28e1d5e1f32f98760b3ee
Reviewed-on: https://go-review.googlesource.com/68431Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 90d71fe9
...@@ -376,7 +376,7 @@ func splitUSTARPath(name string) (prefix, suffix string, ok bool) { ...@@ -376,7 +376,7 @@ func splitUSTARPath(name string) (prefix, suffix string, ok bool) {
length-- length--
} }
i := strings.LastIndexByte(name[:length], '/') i := strings.LastIndex(name[:length], "/")
nlen := len(name) - i - 1 // nlen is length of suffix nlen := len(name) - i - 1 // nlen is length of suffix
plen := i // plen is length of prefix plen := i // plen is length of prefix
if i <= 0 || nlen > nameSize || nlen == 0 || plen > prefixSize { if i <= 0 || nlen > nameSize || nlen == 0 || plen > prefixSize {
......
...@@ -205,7 +205,7 @@ func parseArgs(args []string) (pkg *build.Package, path, symbol string, more boo ...@@ -205,7 +205,7 @@ func parseArgs(args []string) (pkg *build.Package, path, symbol string, more boo
} }
// If it has a slash, it must be a package path but there is a symbol. // If it has a slash, it must be a package path but there is a symbol.
// It's the last package path we care about. // It's the last package path we care about.
slash := strings.LastIndexByte(arg, '/') slash := strings.LastIndex(arg, "/")
// There may be periods in the package path before or after the slash // There may be periods in the package path before or after the slash
// and between a symbol and method. // and between a symbol and method.
// Split the string at various periods to see what we find. // Split the string at various periods to see what we find.
......
...@@ -719,7 +719,7 @@ func usesImport(f *ast.File, path string) (used bool) { ...@@ -719,7 +719,7 @@ func usesImport(f *ast.File, path string) (used bool) {
case "<nil>": case "<nil>":
// If the package name is not explicitly specified, // If the package name is not explicitly specified,
// make an educated guess. This is not guaranteed to be correct. // make an educated guess. This is not guaranteed to be correct.
lastSlash := strings.LastIndexByte(path, '/') lastSlash := strings.LastIndex(path, "/")
if lastSlash == -1 { if lastSlash == -1 {
name = path name = path
} else { } else {
......
...@@ -38,7 +38,7 @@ func initPrintFlags() { ...@@ -38,7 +38,7 @@ func initPrintFlags() {
// Backwards compatibility: skip optional first argument // Backwards compatibility: skip optional first argument
// index after the colon. // index after the colon.
if colon := strings.LastIndexByte(name, ':'); colon > 0 { if colon := strings.LastIndex(name, ":"); colon > 0 {
name = name[:colon] name = name[:colon]
} }
......
...@@ -848,7 +848,7 @@ func hostnameInSNI(name string) string { ...@@ -848,7 +848,7 @@ func hostnameInSNI(name string) string {
if len(host) > 0 && host[0] == '[' && host[len(host)-1] == ']' { if len(host) > 0 && host[0] == '[' && host[len(host)-1] == ']' {
host = host[1 : len(host)-1] host = host[1 : len(host)-1]
} }
if i := strings.LastIndexByte(host, '%'); i > 0 { if i := strings.LastIndex(host, "%"); i > 0 {
host = host[:i] host = host[:i]
} }
if net.ParseIP(host) != nil { if net.ParseIP(host) != nil {
......
...@@ -122,7 +122,7 @@ func DialWithDialer(dialer *net.Dialer, network, addr string, config *Config) (* ...@@ -122,7 +122,7 @@ func DialWithDialer(dialer *net.Dialer, network, addr string, config *Config) (*
return nil, err return nil, err
} }
colonPos := strings.LastIndexByte(addr, ':') colonPos := strings.LastIndex(addr, ":")
if colonPos == -1 { if colonPos == -1 {
colonPos = len(addr) colonPos = len(addr)
} }
......
...@@ -40,7 +40,7 @@ func (s *Sym) Static() bool { return s.Type >= 'a' } ...@@ -40,7 +40,7 @@ func (s *Sym) Static() bool { return s.Type >= 'a' }
// PackageName returns the package part of the symbol name, // PackageName returns the package part of the symbol name,
// or the empty string if there is none. // or the empty string if there is none.
func (s *Sym) PackageName() string { func (s *Sym) PackageName() string {
pathend := strings.LastIndexByte(s.Name, '/') pathend := strings.LastIndex(s.Name, "/")
if pathend < 0 { if pathend < 0 {
pathend = 0 pathend = 0
} }
...@@ -54,12 +54,12 @@ func (s *Sym) PackageName() string { ...@@ -54,12 +54,12 @@ func (s *Sym) PackageName() string {
// ReceiverName returns the receiver type name of this symbol, // ReceiverName returns the receiver type name of this symbol,
// or the empty string if there is none. // or the empty string if there is none.
func (s *Sym) ReceiverName() string { func (s *Sym) ReceiverName() string {
pathend := strings.LastIndexByte(s.Name, '/') pathend := strings.LastIndex(s.Name, "/")
if pathend < 0 { if pathend < 0 {
pathend = 0 pathend = 0
} }
l := strings.Index(s.Name[pathend:], ".") l := strings.Index(s.Name[pathend:], ".")
r := strings.LastIndexByte(s.Name[pathend:], '.') r := strings.LastIndex(s.Name[pathend:], ".")
if l == -1 || r == -1 || l == r { if l == -1 || r == -1 || l == r {
return "" return ""
} }
...@@ -68,7 +68,7 @@ func (s *Sym) ReceiverName() string { ...@@ -68,7 +68,7 @@ func (s *Sym) ReceiverName() string {
// BaseName returns the symbol name without the package or receiver name. // BaseName returns the symbol name without the package or receiver name.
func (s *Sym) BaseName() string { func (s *Sym) BaseName() string {
if i := strings.LastIndexByte(s.Name, '.'); i != -1 { if i := strings.LastIndex(s.Name, "."); i != -1 {
return s.Name[i+1:] return s.Name[i+1:]
} }
return s.Name return s.Name
......
...@@ -333,7 +333,7 @@ func (p *printer) createAttrPrefix(url string) string { ...@@ -333,7 +333,7 @@ func (p *printer) createAttrPrefix(url string) string {
// Pick a name. We try to use the final element of the path // Pick a name. We try to use the final element of the path
// but fall back to _. // but fall back to _.
prefix := strings.TrimRight(url, "/") prefix := strings.TrimRight(url, "/")
if i := strings.LastIndexByte(prefix, '/'); i >= 0 { if i := strings.LastIndex(prefix, "/"); i >= 0 {
prefix = prefix[i+1:] prefix = prefix[i+1:]
} }
if prefix == "" || !isName([]byte(prefix)) || strings.Contains(prefix, ":") { if prefix == "" || !isName([]byte(prefix)) || strings.Contains(prefix, ":") {
......
...@@ -465,7 +465,7 @@ func (e *MultiplePackageError) Error() string { ...@@ -465,7 +465,7 @@ func (e *MultiplePackageError) Error() string {
} }
func nameExt(name string) string { func nameExt(name string) string {
i := strings.LastIndexByte(name, '.') i := strings.LastIndex(name, ".")
if i < 0 { if i < 0 {
return "" return ""
} }
...@@ -610,7 +610,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa ...@@ -610,7 +610,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
} }
tried.vendor = append(tried.vendor, dir) tried.vendor = append(tried.vendor, dir)
} }
i := strings.LastIndexByte(sub, '/') i := strings.LastIndex(sub, "/")
if i < 0 { if i < 0 {
break break
} }
...@@ -1064,7 +1064,7 @@ func (ctxt *Context) matchFile(dir, name string, allTags map[string]bool, binary ...@@ -1064,7 +1064,7 @@ func (ctxt *Context) matchFile(dir, name string, allTags map[string]bool, binary
return return
} }
i := strings.LastIndexByte(name, '.') i := strings.LastIndex(name, ".")
if i < 0 { if i < 0 {
i = len(name) i = len(name)
} }
......
...@@ -93,7 +93,7 @@ func decorate(s string, addFileLine bool) string { ...@@ -93,7 +93,7 @@ func decorate(s string, addFileLine bool) string {
_, file, line, ok := runtime.Caller(3) // decorate + log + public function. _, file, line, ok := runtime.Caller(3) // decorate + log + public function.
if ok { if ok {
// Truncate file name at last file name separator. // Truncate file name at last file name separator.
if index := strings.LastIndexByte(file, '/'); index >= 0 { if index := strings.LastIndex(file, "/"); index >= 0 {
file = file[index+1:] file = file[index+1:]
} else if index = strings.LastIndex(file, "\\"); index >= 0 { } else if index = strings.LastIndex(file, "\\"); index >= 0 {
file = file[index+1:] file = file[index+1:]
......
...@@ -624,7 +624,7 @@ func (p *printer) writeComment(comment *ast.Comment) { ...@@ -624,7 +624,7 @@ func (p *printer) writeComment(comment *ast.Comment) {
if strings.HasPrefix(text, linePrefix) && (!pos.IsValid() || pos.Column == 1) { if strings.HasPrefix(text, linePrefix) && (!pos.IsValid() || pos.Column == 1) {
// possibly a line directive // possibly a line directive
ldir := strings.TrimSpace(text[len(linePrefix):]) ldir := strings.TrimSpace(text[len(linePrefix):])
if i := strings.LastIndexByte(ldir, ':'); i >= 0 { if i := strings.LastIndex(ldir, ":"); i >= 0 {
if line, err := strconv.Atoi(ldir[i+1:]); err == nil && line > 0 { if line, err := strconv.Atoi(ldir[i+1:]); err == nil && line > 0 {
// The line directive we are about to print changed // The line directive we are about to print changed
// the Filename and Line number used for subsequent // the Filename and Line number used for subsequent
......
...@@ -172,7 +172,7 @@ func (check *Checker) importPackage(pos token.Pos, path, dir string) *Package { ...@@ -172,7 +172,7 @@ func (check *Checker) importPackage(pos token.Pos, path, dir string) *Package {
if i := len(name); i > 0 && name[i-1] == '/' { if i := len(name); i > 0 && name[i-1] == '/' {
name = name[:i-1] name = name[:i-1]
} }
if i := strings.LastIndexByte(name, '/'); i >= 0 { if i := strings.LastIndex(name, "/"); i >= 0 {
name = name[i+1:] name = name[i+1:]
} }
imp = NewPackage(path, name) imp = NewPackage(path, name)
...@@ -516,7 +516,7 @@ func (check *Checker) unusedImports() { ...@@ -516,7 +516,7 @@ func (check *Checker) unusedImports() {
// pkgName returns the package name (last element) of an import path. // pkgName returns the package name (last element) of an import path.
func pkgName(path string) string { func pkgName(path string) string {
if i := strings.LastIndexByte(path, '/'); i >= 0 { if i := strings.LastIndex(path, "/"); i >= 0 {
path = path[i+1:] path = path[i+1:]
} }
return path return path
......
...@@ -812,7 +812,7 @@ func symbolize(events []*Event, bin string) error { ...@@ -812,7 +812,7 @@ func symbolize(events []*Event, bin string) error {
f := &Frame{PC: pc} f := &Frame{PC: pc}
f.Fn = fn[:len(fn)-1] f.Fn = fn[:len(fn)-1]
f.File = file[:len(file)-1] f.File = file[:len(file)-1]
if colon := strings.LastIndexByte(f.File, ':'); colon != -1 { if colon := strings.LastIndex(f.File, ":"); colon != -1 {
ln, err := strconv.Atoi(f.File[colon+1:]) ln, err := strconv.Atoi(f.File[colon+1:])
if err == nil { if err == nil {
f.File = f.File[:colon] f.File = f.File[:colon]
......
...@@ -330,7 +330,7 @@ func jarKey(host string, psl PublicSuffixList) string { ...@@ -330,7 +330,7 @@ func jarKey(host string, psl PublicSuffixList) string {
var i int var i int
if psl == nil { if psl == nil {
i = strings.LastIndexByte(host, '.') i = strings.LastIndex(host, ".")
if i <= 0 { if i <= 0 {
return host return host
} }
...@@ -349,7 +349,7 @@ func jarKey(host string, psl PublicSuffixList) string { ...@@ -349,7 +349,7 @@ func jarKey(host string, psl PublicSuffixList) string {
// here on, so it is okay if psl.PublicSuffix("www.buggy.psl") // here on, so it is okay if psl.PublicSuffix("www.buggy.psl")
// returns "com" as the jar key is generated from host. // returns "com" as the jar key is generated from host.
} }
prevDot := strings.LastIndexByte(host[:i-1], '.') prevDot := strings.LastIndex(host[:i-1], ".")
return host[prevDot+1:] return host[prevDot+1:]
} }
...@@ -365,7 +365,7 @@ func defaultPath(path string) string { ...@@ -365,7 +365,7 @@ func defaultPath(path string) string {
return "/" // Path is empty or malformed. return "/" // Path is empty or malformed.
} }
i := strings.LastIndexByte(path, '/') // Path starts with "/", so i != -1. i := strings.LastIndex(path, "/") // Path starts with "/", so i != -1.
if i == 0 { if i == 0 {
return "/" // Path has the form "/abc". return "/" // Path has the form "/abc".
} }
......
...@@ -37,7 +37,7 @@ func (testPSL) PublicSuffix(d string) string { ...@@ -37,7 +37,7 @@ func (testPSL) PublicSuffix(d string) string {
if d == "www2.buggy.psl" { if d == "www2.buggy.psl" {
return "com" return "com"
} }
return d[strings.LastIndexByte(d, '.')+1:] return d[strings.LastIndex(d, ".")+1:]
} }
// newTestJar creates an empty Jar with testPSL as the public suffix list. // newTestJar creates an empty Jar with testPSL as the public suffix list.
......
...@@ -35,7 +35,7 @@ func (k *contextKey) String() string { return "net/http context value " + k.name ...@@ -35,7 +35,7 @@ func (k *contextKey) String() string { return "net/http context value " + k.name
// Given a string of the form "host", "host:port", or "[ipv6::address]:port", // Given a string of the form "host", "host:port", or "[ipv6::address]:port",
// return true if the string includes a port. // return true if the string includes a port.
func hasPort(s string) bool { return strings.LastIndexByte(s, ':') > strings.LastIndexByte(s, ']') } func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
// removeEmptyPort strips the empty port in ":port" to "" // removeEmptyPort strips the empty port in ":port" to ""
// as mandated by RFC 3986 Section 6.2.3. // as mandated by RFC 3986 Section 6.2.3.
......
...@@ -688,11 +688,11 @@ func removeZone(host string) string { ...@@ -688,11 +688,11 @@ func removeZone(host string) string {
if !strings.HasPrefix(host, "[") { if !strings.HasPrefix(host, "[") {
return host return host
} }
i := strings.LastIndexByte(host, ']') i := strings.LastIndex(host, "]")
if i < 0 { if i < 0 {
return host return host
} }
j := strings.LastIndexByte(host[:i], '%') j := strings.LastIndex(host[:i], "%")
if j < 0 { if j < 0 {
return host return host
} }
......
...@@ -1236,7 +1236,7 @@ func useProxy(addr string) bool { ...@@ -1236,7 +1236,7 @@ func useProxy(addr string) bool {
addr = strings.ToLower(strings.TrimSpace(addr)) addr = strings.ToLower(strings.TrimSpace(addr))
if hasPort(addr) { if hasPort(addr) {
addr = addr[:strings.LastIndexByte(addr, ':')] addr = addr[:strings.LastIndex(addr, ":")]
} }
for _, p := range strings.Split(noProxy, ",") { for _, p := range strings.Split(noProxy, ",") {
...@@ -1245,7 +1245,7 @@ func useProxy(addr string) bool { ...@@ -1245,7 +1245,7 @@ func useProxy(addr string) bool {
continue continue
} }
if hasPort(p) { if hasPort(p) {
p = p[:strings.LastIndexByte(p, ':')] p = p[:strings.LastIndex(p, ":")]
} }
if addr == p { if addr == p {
return false return false
...@@ -1317,7 +1317,7 @@ func (cm *connectMethod) addr() string { ...@@ -1317,7 +1317,7 @@ func (cm *connectMethod) addr() string {
func (cm *connectMethod) tlsHost() string { func (cm *connectMethod) tlsHost() string {
h := cm.targetAddr h := cm.targetAddr
if hasPort(h) { if hasPort(h) {
h = h[:strings.LastIndexByte(h, ':')] h = h[:strings.LastIndex(h, ":")]
} }
return h return h
} }
......
...@@ -177,7 +177,7 @@ func (p *AddressParser) ParseList(list string) ([]*Address, error) { ...@@ -177,7 +177,7 @@ func (p *AddressParser) ParseList(list string) ([]*Address, error) {
// the name will be rendered according to RFC 2047. // the name will be rendered according to RFC 2047.
func (a *Address) String() string { func (a *Address) String() string {
// Format address local@domain // Format address local@domain
at := strings.LastIndexByte(a.Address, '@') at := strings.LastIndex(a.Address, "@")
var local, domain string var local, domain string
if at < 0 { if at < 0 {
// This is a malformed address ("@" is required in addr-spec); // This is a malformed address ("@" is required in addr-spec);
......
...@@ -592,7 +592,7 @@ func (server *Server) readRequestHeader(codec ServerCodec) (svc *service, mtype ...@@ -592,7 +592,7 @@ func (server *Server) readRequestHeader(codec ServerCodec) (svc *service, mtype
// we can still recover and move on to the next request. // we can still recover and move on to the next request.
keepReading = true keepReading = true
dot := strings.LastIndexByte(req.ServiceMethod, '.') dot := strings.LastIndex(req.ServiceMethod, ".")
if dot < 0 { if dot < 0 {
err = errors.New("rpc: service/method request ill-formed: " + req.ServiceMethod) err = errors.New("rpc: service/method request ill-formed: " + req.ServiceMethod)
return return
......
...@@ -532,7 +532,7 @@ func parse(rawurl string, viaRequest bool) (*URL, error) { ...@@ -532,7 +532,7 @@ func parse(rawurl string, viaRequest bool) (*URL, error) {
} }
func parseAuthority(authority string) (user *Userinfo, host string, err error) { func parseAuthority(authority string) (user *Userinfo, host string, err error) {
i := strings.LastIndexByte(authority, '@') i := strings.LastIndex(authority, "@")
if i < 0 { if i < 0 {
host, err = parseHost(authority) host, err = parseHost(authority)
} else { } else {
...@@ -569,7 +569,7 @@ func parseHost(host string) (string, error) { ...@@ -569,7 +569,7 @@ func parseHost(host string) (string, error) {
if strings.HasPrefix(host, "[") { if strings.HasPrefix(host, "[") {
// Parse an IP-Literal in RFC 3986 and RFC 6874. // Parse an IP-Literal in RFC 3986 and RFC 6874.
// E.g., "[fe80::1]", "[fe80::1%25en0]", "[fe80::1]:80". // E.g., "[fe80::1]", "[fe80::1%25en0]", "[fe80::1]:80".
i := strings.LastIndexByte(host, ']') i := strings.LastIndex(host, "]")
if i < 0 { if i < 0 {
return "", errors.New("missing ']' in host") return "", errors.New("missing ']' in host")
} }
...@@ -885,7 +885,7 @@ func resolvePath(base, ref string) string { ...@@ -885,7 +885,7 @@ func resolvePath(base, ref string) string {
if ref == "" { if ref == "" {
full = base full = base
} else if ref[0] != '/' { } else if ref[0] != '/' {
i := strings.LastIndexByte(base, '/') i := strings.LastIndex(base, "/")
full = base[:i+1] + ref full = base[:i+1] + ref
} else { } else {
full = ref full = ref
......
...@@ -26,7 +26,7 @@ func chkStat(file string) error { ...@@ -26,7 +26,7 @@ func chkStat(file string) error {
} }
func hasExt(file string) bool { func hasExt(file string) bool {
i := strings.LastIndexByte(file, '.') i := strings.LastIndex(file, ".")
if i < 0 { if i < 0 {
return false return false
} }
......
...@@ -145,7 +145,7 @@ func Clean(path string) string { ...@@ -145,7 +145,7 @@ func Clean(path string) string {
// file set to path. // file set to path.
// The returned values have the property that path = dir+file. // The returned values have the property that path = dir+file.
func Split(path string) (dir, file string) { func Split(path string) (dir, file string) {
i := strings.LastIndexByte(path, '/') i := strings.LastIndex(path, "/")
return path[:i+1], path[i+1:] return path[:i+1], path[i+1:]
} }
...@@ -187,7 +187,7 @@ func Base(path string) string { ...@@ -187,7 +187,7 @@ func Base(path string) string {
path = path[0 : len(path)-1] path = path[0 : len(path)-1]
} }
// Find the last element // Find the last element
if i := strings.LastIndexByte(path, '/'); i >= 0 { if i := strings.LastIndex(path, "/"); i >= 0 {
path = path[i+1:] path = path[i+1:]
} }
// If empty now, it had only slashes. // If empty now, it had only slashes.
......
...@@ -360,7 +360,7 @@ func (c *common) decorate(s string) string { ...@@ -360,7 +360,7 @@ func (c *common) decorate(s string) string {
_, file, line, ok := runtime.Caller(skip) _, file, line, ok := runtime.Caller(skip)
if ok { if ok {
// Truncate file name at last file name separator. // Truncate file name at last file name separator.
if index := strings.LastIndexByte(file, '/'); index >= 0 { if index := strings.LastIndex(file, "/"); index >= 0 {
file = file[index+1:] file = file[index+1:]
} else if index = strings.LastIndex(file, "\\"); index >= 0 { } else if index = strings.LastIndex(file, "\\"); index >= 0 {
file = file[index+1:] file = file[index+1:]
......
...@@ -253,7 +253,7 @@ func TestMonotonicString(t *testing.T) { ...@@ -253,7 +253,7 @@ func TestMonotonicString(t *testing.T) {
t1 := Now() t1 := Now()
SetMono(&t1, tt.mono) SetMono(&t1, tt.mono)
s := t1.String() s := t1.String()
got := s[strings.LastIndexByte(s, ' ')+1:] got := s[strings.LastIndex(s, " ")+1:]
if got != tt.want { if got != tt.want {
t.Errorf("with mono=%d: got %q; want %q", tt.mono, got, tt.want) t.Errorf("with mono=%d: got %q; want %q", tt.mono, got, tt.want)
} }
......
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