Skip to content

Commit

Permalink
Use bytes.IndexByte instead of bytes.Index for single byte lookup (#999)
Browse files Browse the repository at this point in the history
* Update uri.go

* Update strings.go
  • Loading branch information
moredure authored Mar 20, 2021
1 parent 860c345 commit a583006
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 0 additions & 1 deletion strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var (
strColonSlashSlash = []byte("://")
strColonSpace = []byte(": ")
strGMT = []byte("GMT")
strAt = []byte("@")

strResponseContinue = []byte("HTTP/1.1 100 Continue\r\n\r\n")

Expand Down
4 changes: 2 additions & 2 deletions uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ func (u *URI) parse(host, uri []byte, isTLS bool) error {
u.scheme = append(u.scheme[:0], strHTTPS...)
}

if n := bytes.Index(host, strAt); n >= 0 {
if n := bytes.IndexByte(host, '@'); n >= 0 {
auth := host[:n]
host = host[n+1:]

if n := bytes.Index(auth, strColon); n >= 0 {
if n := bytes.IndexByte(auth, ':'); n >= 0 {
u.username = append(u.username[:0], auth[:n]...)
u.password = append(u.password[:0], auth[n+1:]...)
} else {
Expand Down

0 comments on commit a583006

Please sign in to comment.