This change refactors the parseIPv4 function to extract a new helper
function, parseIPv4Fields, which is now used by both parseIPv4 and
parseIPv6 functions. The extraction of this logic into a separate
helper function removes code duplication and improves the performance
of parsing IPv6 addresses that contain an embedded IPv4 address.
Additionally, the error handling within the IP address parsing logic
has been streamlined to provide clearer messages when encountering
incorrect formats or values in IPv4 fields.
Benchmark:
```
benchstat old.out new.out
goos: darwin
goarch: amd64
pkg: net/netip
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
│ old.out │ new.out │
│ sec/op │ sec/op vs base │
ParseAddr/v4-12 22.23n ± 2% 21.86n ± 2% ~ (p=0.127 n=10)
ParseAddr/v6-12 69.67n ± 7% 70.31n ± 1% ~ (p=0.128 n=10)
ParseAddr/v6_ellipsis-12 48.22n ± 17% 48.58n ± 1% ~ (p=0.739 n=10)
ParseAddr/v6_v4-12 60.73n ± 36% 51.54n ± 1% -15.14% (p=0.000 n=10)
ParseAddr/v6_zone-12 102.50n ± 22% 93.50n ± 0% -8.79% (p=0.000 n=10)
ParseAddrPort/v4-12 38.07n ± 1% 36.84n ± 2% -3.22% (p=0.000 n=10)
ParseAddrPort/v6-12 84.61n ± 1% 87.21n ± 1% +3.07% (p=0.000 n=10)
ParseAddrPort/v6_ellipsis-12 69.65n ± 8% 64.56n ± 2% -7.31% (p=0.023 n=10)
ParseAddrPort/v6_v4-12 71.88n ± 1% 70.61n ± 1% -1.76% (p=0.000 n=10)
ParseAddrPort/v6_zone-12 119.0n ± 2% 118.0n ± 2% ~ (p=0.108 n=10)
geomean 62.38n 60.17n -3.54%
│ old.out │ new.out │
│ B/op │ B/op vs base │
ParseAddr/v4-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddr/v6-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddr/v6_ellipsis-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddr/v6_v4-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddr/v6_zone-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v4-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v6-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v6_ellipsis-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v6_v4-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v6_zone-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
geomean ² +0.00% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
│ old.out │ new.out │
│ allocs/op │ allocs/op vs base │
ParseAddr/v4-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddr/v6-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddr/v6_ellipsis-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddr/v6_v4-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddr/v6_zone-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v4-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v6-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v6_ellipsis-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v6_v4-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ParseAddrPort/v6_zone-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
geomean ² +0.00% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
```
Change-Id: I403cb76f449a0bf203a821294df25d3c9031df4c
GitHub-Last-Rev:
|
||
|---|---|---|
| .github | ||
| api | ||
| doc | ||
| lib/time | ||
| misc | ||
| src | ||
| test | ||
| .gitattributes | ||
| .gitignore | ||
| CONTRIBUTING.md | ||
| LICENSE | ||
| PATENTS | ||
| README.md | ||
| SECURITY.md | ||
| codereview.cfg | ||
| go.env | ||
README.md
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 4.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.