mirror of
https://github.com/samber/lo.git
synced 2026-04-22 15:37:14 +08:00
oops
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
# Performance Optimizations Report
|
||||
|
||||
## PR #827 - Reject / RejectErr / RejectMap
|
||||
- Preallocate result slice with `make(Slice, 0, len(collection))` instead of `Slice{}`
|
||||
- Avoids repeated grow-and-copy reallocations as elements are appended
|
||||
|
||||
## PR #829 - UniqMap
|
||||
- Collect results directly during the single map-building pass instead of calling `Keys(seen)` afterward
|
||||
- Eliminates a second full iteration over the map to extract keys
|
||||
- Eliminates a separate slice allocation inside `Keys()`
|
||||
- Preserves insertion order (old code returned non-deterministic map iteration order)
|
||||
|
||||
## PR #830 - Difference
|
||||
- Preallocate result slices with `make(Slice, 0, len(listN))` instead of `Slice{}`
|
||||
- Avoids repeated grow-and-copy reallocations as elements are appended
|
||||
|
||||
## PR #831 - FromSlicePtr / FromSlicePtrOr
|
||||
- Replace indirect `Map()` call with closure by a direct loop
|
||||
- Eliminates per-element function call overhead from the closure indirection
|
||||
|
||||
## PR #833 - CountValues, UniqKeys, UniqValues, FilterKeys, FilterValues, FilterKeysErr, FilterValuesErr
|
||||
- Add size hint to map allocation in CountValues: `make(map[T]int)` → `make(map[T]int, len(collection))`
|
||||
- Avoids repeated map rehashing as entries are added
|
||||
- Add capacity hint to result slice in UniqKeys/UniqValues: `make([]K, 0)` → `make([]K, 0, size)`
|
||||
- Avoids repeated slice grow-and-copy reallocations
|
||||
- Add capacity hint to result slice in FilterKeys/FilterValues/FilterKeysErr/FilterValuesErr: `make([]K, 0)` → `make([]K, 0, len(in))`
|
||||
- Avoids repeated slice grow-and-copy reallocations
|
||||
|
||||
## PR #??? - RepeatBy / Fill / Repeat
|
||||
- Replace `make([]T, 0, count)` + `append(result, ...)` with `make([]T, count)` + `result[i] = ...`
|
||||
- Eliminates per-element append overhead (bounds check, length increment, slice header update)
|
||||
- Size is known upfront so direct index assignment is safe and faster
|
||||
- RepeatByErr left unchanged: early error return makes direct index problematic (would allocate full slice then discard)
|
||||
Reference in New Issue
Block a user