aboutsummaryrefslogtreecommitdiff
path: root/src/net/http
diff options
context:
space:
mode:
authorMarvin Stenger <marvin.stenger94@gmail.com>2017-09-25 15:47:44 +0200
committerIan Lance Taylor <iant@golang.org>2017-09-27 00:54:24 +0000
commitd2826d3e068f096f4b5371175afb7e5d8c4aa73c (patch)
treee252245e001e359351b9a06891cadf6d725231b9 /src/net/http
parente61c5e2f2044c7bc606ebdfbd0187598b90c50e5 (diff)
downloadgo-d2826d3e068f096f4b5371175afb7e5d8c4aa73c.tar.xz
all: prefer strings.LastIndexByte over strings.LastIndex
strings.LastIndexByte was introduced in go1.5 and it can be used effectively wherever the second argument to strings.LastIndex is exactly one byte long. This avoids generating unnecessary string symbols and saves a few calls to strings.LastIndex. Change-Id: I7b5679d616197b055cffe6882a8675d24a98b574 Reviewed-on: https://go-review.googlesource.com/66372 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/http')
-rw-r--r--src/net/http/cookiejar/jar.go6
-rw-r--r--src/net/http/cookiejar/jar_test.go2
-rw-r--r--src/net/http/http.go2
-rw-r--r--src/net/http/request.go4
-rw-r--r--src/net/http/transport.go6
5 files changed, 10 insertions, 10 deletions
diff --git a/src/net/http/cookiejar/jar.go b/src/net/http/cookiejar/jar.go
index ef8c35bf0a..f147eceb18 100644
--- a/src/net/http/cookiejar/jar.go
+++ b/src/net/http/cookiejar/jar.go
@@ -330,7 +330,7 @@ func jarKey(host string, psl PublicSuffixList) string {
var i int
if psl == nil {
- i = strings.LastIndex(host, ".")
+ i = strings.LastIndexByte(host, '.')
if i <= 0 {
return host
}
@@ -349,7 +349,7 @@ func jarKey(host string, psl PublicSuffixList) string {
// here on, so it is okay if psl.PublicSuffix("www.buggy.psl")
// returns "com" as the jar key is generated from host.
}
- prevDot := strings.LastIndex(host[:i-1], ".")
+ prevDot := strings.LastIndexByte(host[:i-1], '.')
return host[prevDot+1:]
}
@@ -365,7 +365,7 @@ func defaultPath(path string) string {
return "/" // Path is empty or malformed.
}
- i := strings.LastIndex(path, "/") // Path starts with "/", so i != -1.
+ i := strings.LastIndexByte(path, '/') // Path starts with "/", so i != -1.
if i == 0 {
return "/" // Path has the form "/abc".
}
diff --git a/src/net/http/cookiejar/jar_test.go b/src/net/http/cookiejar/jar_test.go
index 47fb1abdaa..ed4baae4c6 100644
--- a/src/net/http/cookiejar/jar_test.go
+++ b/src/net/http/cookiejar/jar_test.go
@@ -37,7 +37,7 @@ func (testPSL) PublicSuffix(d string) string {
if d == "www2.buggy.psl" {
return "com"
}
- return d[strings.LastIndex(d, ".")+1:]
+ return d[strings.LastIndexByte(d, '.')+1:]
}
// newTestJar creates an empty Jar with testPSL as the public suffix list.
diff --git a/src/net/http/http.go b/src/net/http/http.go
index b95ca89f40..7d5b74092e 100644
--- a/src/net/http/http.go
+++ b/src/net/http/http.go
@@ -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",
// return true if the string includes a port.
-func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
+func hasPort(s string) bool { return strings.LastIndexByte(s, ':') > strings.LastIndexByte(s, ']') }
// removeEmptyPort strips the empty port in ":port" to ""
// as mandated by RFC 3986 Section 6.2.3.
diff --git a/src/net/http/request.go b/src/net/http/request.go
index b7fcf806ba..e384517668 100644
--- a/src/net/http/request.go
+++ b/src/net/http/request.go
@@ -688,11 +688,11 @@ func removeZone(host string) string {
if !strings.HasPrefix(host, "[") {
return host
}
- i := strings.LastIndex(host, "]")
+ i := strings.LastIndexByte(host, ']')
if i < 0 {
return host
}
- j := strings.LastIndex(host[:i], "%")
+ j := strings.LastIndexByte(host[:i], '%')
if j < 0 {
return host
}
diff --git a/src/net/http/transport.go b/src/net/http/transport.go
index 5f2ace7b4b..034d016cb3 100644
--- a/src/net/http/transport.go
+++ b/src/net/http/transport.go
@@ -1236,7 +1236,7 @@ func useProxy(addr string) bool {
addr = strings.ToLower(strings.TrimSpace(addr))
if hasPort(addr) {
- addr = addr[:strings.LastIndex(addr, ":")]
+ addr = addr[:strings.LastIndexByte(addr, ':')]
}
for _, p := range strings.Split(noProxy, ",") {
@@ -1245,7 +1245,7 @@ func useProxy(addr string) bool {
continue
}
if hasPort(p) {
- p = p[:strings.LastIndex(p, ":")]
+ p = p[:strings.LastIndexByte(p, ':')]
}
if addr == p {
return false
@@ -1317,7 +1317,7 @@ func (cm *connectMethod) addr() string {
func (cm *connectMethod) tlsHost() string {
h := cm.targetAddr
if hasPort(h) {
- h = h[:strings.LastIndex(h, ":")]
+ h = h[:strings.LastIndexByte(h, ':')]
}
return h
}