pool.go raw

   1  package lattice
   2  
   3  import "sync"
   4  
   5  // neighborPool caches []uint32 slices to reduce GC pressure.
   6  // Slices are returned with length 0 and capacity 8.
   7  var neighborPool = sync.Pool{
   8  	New: func() any { return make([]uint32, 0, 8) },
   9  }
  10  
  11  // getNeighborSlice returns a pre-allocated neighbor index slice from the pool.
  12  func getNeighborSlice() []uint32 {
  13  	return neighborPool.Get().([]uint32)[:0]
  14  }
  15  
  16  // putNeighborSlice returns a neighbor index slice to the pool.
  17  func putNeighborSlice(s []uint32) {
  18  	clear(s)
  19  	neighborPool.Put(s[:0])
  20  }
  21