]> Cypherpunks repositories - gostls13.git/commitdiff
net: use bytealg.LastIndexByteString
authorapocelipes <seve3r@outlook.com>
Thu, 14 Sep 2023 18:43:14 +0000 (18:43 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 15 Sep 2023 12:57:52 +0000 (12:57 +0000)
There is no need to handwrite the "last" function, the bytealg package already provides "LastIndexByteString".

Change-Id: I6000705bffe8450a10cf8f3fa716a8d4605ada1f
GitHub-Last-Rev: 6627c65fb40fad96239edd28bde27a30f9f8f544
GitHub-Pull-Request: golang/go#62647
Reviewed-on: https://go-review.googlesource.com/c/go/+/527976
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/net/dial.go
src/net/ipsock.go
src/net/parse.go

index dd34b6cef2540cf821ab6b681785af835f81010b..7ca9b4a4682c5bbc495a2f249df77da0ca692f6a 100644 (file)
@@ -6,6 +6,7 @@ package net
 
 import (
        "context"
+       "internal/bytealg"
        "internal/godebug"
        "internal/nettrace"
        "syscall"
@@ -226,7 +227,7 @@ func (d *Dialer) fallbackDelay() time.Duration {
 }
 
 func parseNetwork(ctx context.Context, network string, needsProto bool) (afnet string, proto int, err error) {
-       i := last(network, ':')
+       i := bytealg.LastIndexByteString(network, ':')
        if i < 0 { // no colon
                switch network {
                case "tcp", "tcp4", "tcp6":
index cdd097c2d3ae93a80c315ba86b5db052c5daa93e..176dbc748e66c83cc311261400cc5496b34da2d4 100644 (file)
@@ -172,7 +172,7 @@ func SplitHostPort(hostport string) (host, port string, err error) {
        j, k := 0, 0
 
        // The port starts after the last colon.
-       i := last(hostport, ':')
+       i := bytealg.LastIndexByteString(hostport, ':')
        if i < 0 {
                return addrErr(hostport, missingPort)
        }
@@ -219,7 +219,7 @@ func SplitHostPort(hostport string) (host, port string, err error) {
 func splitHostZone(s string) (host, zone string) {
        // The IPv6 scoped addressing zone identifier starts after the
        // last percent sign.
-       if i := last(s, '%'); i > 0 {
+       if i := bytealg.LastIndexByteString(s, '%'); i > 0 {
                host, zone = s[:i], s[i+1:]
        } else {
                host = s
index f2e790e48fca6f773b5aa560a4ae51cd72a8411f..29dffad43cf4fd12ac966c64d1efbf3f8871908a 100644 (file)
@@ -180,17 +180,6 @@ func xtoi2(s string, e byte) (byte, bool) {
        return byte(n), ok && ei == 2
 }
 
-// Index of rightmost occurrence of b in s.
-func last(s string, b byte) int {
-       i := len(s)
-       for i--; i >= 0; i-- {
-               if s[i] == b {
-                       break
-               }
-       }
-       return i
-}
-
 // hasUpperCase tells whether the given string contains at least one upper-case.
 func hasUpperCase(s string) bool {
        for i := range s {