mirror of
https://github.com/soypat/lneto.git
synced 2026-09-10 16:49:37 +00:00
Reduce heap allocs 2 (#46)
* reduce heap allocations in tcp logging; omit use of AppendFloat which allocates a metric sh*tton * debugheaplog: better heap statistic logging * heap: use string for pcap.Frame.Protocol * add potential to eliminate Flags.String heap alloc, remove incorrect HEAP comments * add StackAsync.DebugErr and httpraw.SetBytes * many heap alloc reductions and replacement of bytes.Equal with internal.BytesEqual
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package internal
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// IsZeroed returns true if all arguments are set to their zero value.
|
||||
func IsZeroed[T comparable](a ...T) bool {
|
||||
var z T
|
||||
@@ -65,3 +67,15 @@ func SliceReclaim[T any](ptr *[]T) *T {
|
||||
}
|
||||
return &(*ptr)[n]
|
||||
}
|
||||
|
||||
// BytesEqual is heapless replacement of [bytes.Equal] since it allocates in tinygo.
|
||||
// https://github.com/tinygo-org/tinygo/issues/4045
|
||||
func BytesEqual(a, b []byte) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
if len(a) == 0 {
|
||||
return true
|
||||
}
|
||||
return unsafe.String(&a[0], len(a)) == unsafe.String(&b[0], len(b))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user