Further reduce heap allocs (#56)

* work on tracking more heap allocations down

* write own heapless IP AppendFormatAddr functions

* remove potential Error method allocations

* more logging
This commit is contained in:
Pat Whittingslow
2026-03-15 00:11:59 +01:00
committed by GitHub
parent de2e756628
commit 376e1a0b4f
8 changed files with 245 additions and 23 deletions
+14
View File
@@ -1,5 +1,7 @@
package ipv4
import "strconv"
const (
sizeHeader = 20
)
@@ -68,3 +70,15 @@ func b2u8(b bool) uint8 {
}
return 0
}
// AppendFormatAddr appends the dotted-decimal text representation of an IPv4 address
// to dst. Zero heap allocations.
func AppendFormatAddr(dst []byte, addr [4]byte) []byte {
for i, b := range addr {
if i != 0 {
dst = append(dst, '.')
}
dst = strconv.AppendUint(dst, uint64(b), 10)
}
return dst
}