]> Cypherpunks repositories - gostls13.git/commitdiff
net: use internal/bytealg.CountString
authorTobias Klauser <tklauser@distanz.ch>
Wed, 23 Aug 2023 09:22:04 +0000 (11:22 +0200)
committerGopher Robot <gobot@golang.org>
Wed, 23 Aug 2023 16:39:35 +0000 (16:39 +0000)
On platforms that provide a native implementation this might be slightly
faster. On other platforms it is equivalent to the count func.

Change-Id: If46cc65598993e64084cc98533cb8c1e9679a6fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/522136
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>

src/net/dnsclient_unix.go
src/net/ipsock.go
src/net/parse.go

index 4c3da9a6c89a70c6e350fe48745e805fd1d231a9..6f2bdbed2d5a72570aa4db8b8492a156e2c7fcfb 100644 (file)
@@ -17,6 +17,7 @@ package net
 import (
        "context"
        "errors"
+       "internal/bytealg"
        "internal/itoa"
        "io"
        "os"
@@ -513,7 +514,7 @@ func (conf *dnsConfig) nameList(name string) []string {
                return []string{name}
        }
 
-       hasNdots := count(name, '.') >= conf.ndots
+       hasNdots := bytealg.CountString(name, '.') >= conf.ndots
        name += "."
        l++
 
index 0f5da2577c6a62e12faad7b2ec0b75cb23841431..cdd097c2d3ae93a80c315ba86b5db052c5daa93e 100644 (file)
@@ -83,10 +83,10 @@ func (addrs addrList) forResolve(network, addr string) Addr {
        switch network {
        case "ip":
                // IPv6 literal (addr does NOT contain a port)
-               want6 = count(addr, ':') > 0
+               want6 = bytealg.CountString(addr, ':') > 0
        case "tcp", "udp":
                // IPv6 literal. (addr contains a port, so look for '[')
-               want6 = count(addr, '[') > 0
+               want6 = bytealg.CountString(addr, '[') > 0
        }
        if want6 {
                return addrs.first(isNotIPv4)
index 22c6123243d2ff753b4afb67d51b9d81fa46baab..f2e790e48fca6f773b5aa560a4ae51cd72a8411f 100644 (file)
@@ -180,17 +180,6 @@ func xtoi2(s string, e byte) (byte, bool) {
        return byte(n), ok && ei == 2
 }
 
-// Number of occurrences of b in s.
-func count(s string, b byte) int {
-       n := 0
-       for i := 0; i < len(s); i++ {
-               if s[i] == b {
-                       n++
-               }
-       }
-       return n
-}
-
 // Index of rightmost occurrence of b in s.
 func last(s string, b byte) int {
        i := len(s)