File tree 2 files changed +16
-9
lines changed
2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -698,21 +698,19 @@ const (
698
698
// IPv6 addresses with zones are returned without their zone (use the
699
699
// Zone method to get it).
700
700
// The ip zero value returns all zeroes.
701
- func (ip Addr ) As16 () [16 ]byte {
702
- var ret [16 ]byte
703
- bePutUint64 (ret [:8 ], ip .addr .hi )
704
- bePutUint64 (ret [8 :], ip .addr .lo )
705
- return ret
701
+ func (ip Addr ) As16 () (a16 [16 ]byte ) {
702
+ bePutUint64 (a16 [:8 ], ip .addr .hi )
703
+ bePutUint64 (a16 [8 :], ip .addr .lo )
704
+ return a16
706
705
}
707
706
708
707
// As4 returns an IPv4 or IPv4-in-IPv6 address in its 4-byte representation.
709
708
// If ip is the zero Addr or an IPv6 address, As4 panics.
710
709
// Note that 0.0.0.0 is not the zero Addr.
711
- func (ip Addr ) As4 () [4 ]byte {
710
+ func (ip Addr ) As4 () ( a4 [4 ]byte ) {
712
711
if ip .z == z4 || ip .Is4In6 () {
713
- var ret [4 ]byte
714
- bePutUint32 (ret [:], uint32 (ip .addr .lo ))
715
- return ret
712
+ bePutUint32 (a4 [:], uint32 (ip .addr .lo ))
713
+ return a4
716
714
}
717
715
if ip .z == z0 {
718
716
panic ("As4 called on IP zero value" )
Original file line number Diff line number Diff line change @@ -1806,3 +1806,12 @@ func TestInvalidAddrPortString(t *testing.T) {
1806
1806
}
1807
1807
}
1808
1808
}
1809
+
1810
+ var sink16 [16 ]byte
1811
+
1812
+ func BenchmarkAs16 (b * testing.B ) {
1813
+ addr := MustParseAddr ("1::10" )
1814
+ for i := 0 ; i < b .N ; i ++ {
1815
+ sink16 = addr .As16 ()
1816
+ }
1817
+ }
You can’t perform that action at this time.
0 commit comments