File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88// but without check for IPv6 case and without returning net.IP slice, whereby IsIPv4 makes no allocations.
99func IsIPv4 (s string ) bool {
1010 //nolint:modernize-loop // old way is more readable
11- for i := 0 ; i < net .IPv4len ; i ++ {
11+ for i := range net .IPv4len {
1212 if len (s ) == 0 {
1313 return false
1414 }
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ func Test_IPWhitespace(t *testing.T) {
101101 require .False (t , IsIPv6 ("::1 " ))
102102}
103103
104- // go test -v -run=^$ -bench=UnsafeString -benchmem -count=2
104+ // go test -v -run=^$ -bench=Benchmark_IsIPv4 -benchmem -count=6
105105func Benchmark_IsIPv4 (b * testing.B ) {
106106 ip := "174.23.33.100"
107107 var res bool
@@ -121,7 +121,7 @@ func Benchmark_IsIPv4(b *testing.B) {
121121 })
122122}
123123
124- // go test -v -run=^$ -bench=UnsafeString -benchmem -count=2
124+ // go test -v -run=^$ -bench=Benchmark_IsIPv6 -benchmem -count=6
125125func Benchmark_IsIPv6 (b * testing.B ) {
126126 ip := "9396:9549:b4f7:8ed0:4791:1330:8c06:e62d"
127127 var res bool
You can’t perform that action at this time.
0 commit comments