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>
import (
"context"
"errors"
+ "internal/bytealg"
"internal/itoa"
"io"
"os"
return []string{name}
}
- hasNdots := count(name, '.') >= conf.ndots
+ hasNdots := bytealg.CountString(name, '.') >= conf.ndots
name += "."
l++
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)
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)