stash icon indicating copy to clipboard operation
stash copied to clipboard

Use slices package from the stdlib when possible

Open its-josh4 opened this issue 1 year ago • 0 comments

Found that pkg/sliceutil had a lot of duplicate functionality with the slices package that is now in the stdlib, so I replaced these methods with the ones from the stdlib:

  • sliceutil.Contains
  • sliceutil.Index

Additionally, made 2 small perf improvements to the sliceutil package:

  • sliceutil.AppendUniques: use slices.Grow to grow the capacity of the slice (if needed) just once. This will make it so the function will cause at most 1 allocation in the heap, no matter how many items are being added
  • sliceutil.Unique: when allocating the lookup map and destination slice, pre-allocate them with max possible capacity to avoid re-allocations

its-josh4 avatar Oct 10 '24 00:10 its-josh4