mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
f7891eb41c
* perf(Reject): preallocate result slice capacity
Reject was using `Slice{}` (zero capacity) causing multiple
grow-and-copy allocations as elements were appended. Preallocate
with `make(Slice, 0, len(collection))` to eliminate regrowth.
benchstat (strings_1000): -42.96% time, -53.37% memory, -88.89% allocs
* perf(Reject): preallocate result slice in Reject, RejectErr, RejectMap
All three Reject variants were using zero-capacity slices (`Slice{}`
or `[]R{}`), causing multiple grow-and-copy allocations as elements
were appended. Preallocate with `make(..., 0, len(collection))` to
eliminate slice regrowth.
Reject benchstat (strings_1000): -42.96% time, -53.37% memory, -88.89% allocs
RejectErr benchstat (strings_1000): -45.11% time, -53.37% memory, -88.89% allocs
RejectMap benchstat (strings_1000): -47.63% time, -53.37% memory, -88.89% allocs