mirror of
https://github.com/duke-git/lancet.git
synced 2025-10-05 15:36:52 +08:00
Pre-allocate memory to reduce the number of allocations (#272)
This commit is contained in:
@@ -31,7 +31,7 @@ func NewArrayQueue[T any](capacity int) *ArrayQueue[T] {
|
||||
|
||||
// Data return slice of queue data
|
||||
func (q *ArrayQueue[T]) Data() []T {
|
||||
items := []T{}
|
||||
items := make([]T, 0, q.tail-q.head)
|
||||
for i := q.head; i < q.tail; i++ {
|
||||
items = append(items, q.data[i])
|
||||
}
|
||||
|
Reference in New Issue
Block a user