Pre-allocate memory to reduce the number of allocations (#272)

This commit is contained in:
Yurun authored and GitHub committed 2024-11-27 14:58:02 +08:00
1 parent 1eb793420e
commit 05b85a2131
12 files changed
+15 -12

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ func NewLinkedStack[T any]() *LinkedStack[T] {
// Data return stack data
func (s *LinkedStack[T]) Data() []T {
res := []T{}
res := make([]T, 0, s.length)
current := s.top
for current != nil {