From d547ccf7ac8c6bf9b8fdcba7a455f0f5e825b741 Mon Sep 17 00:00:00 2001 From: Marvin Stenger Date: Mon, 25 Sep 2017 15:47:44 +0200 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- handshake_client.go | 2 +- tls.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/handshake_client.go b/handshake_client.go index f8db662..38d01bf 100644 --- a/handshake_client.go +++ b/handshake_client.go @@ -848,7 +848,7 @@ func hostnameInSNI(name string) string { if len(host) > 0 && host[0] == '[' && host[len(host)-1] == ']' { host = host[1 : len(host)-1] } - if i := strings.LastIndex(host, "%"); i > 0 { + if i := strings.LastIndexByte(host, '%'); i > 0 { host = host[:i] } if net.ParseIP(host) != nil { diff --git a/tls.go b/tls.go index 615d1e5..1c91dae 100644 --- a/tls.go +++ b/tls.go @@ -122,7 +122,7 @@ func DialWithDialer(dialer *net.Dialer, network, addr string, config *Config) (* return nil, err } - colonPos := strings.LastIndex(addr, ":") + colonPos := strings.LastIndexByte(addr, ':') if colonPos == -1 { colonPos = len(addr) }