mirror of
https://github.com/golang/go
synced 2024-11-23 12:50:12 -07:00
net: use internal/bytealg.CountString
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>
This commit is contained in:
parent
a97f71578f
commit
aa0ba4dcaf
@ -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++
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user