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
@@ -147,7 +147,7 @@ func printTreeNodes[T any](nodes []*datastructure.TreeNode[T], level, maxLevel i
printSpaces(firstSpaces)
newNodes := []*datastructure.TreeNode[T]{}
newNodes := make([]*datastructure.TreeNode[T], 0, len(nodes)*2)
for _, node := range nodes {
if node != nil {
fmt.Printf("%v", node.Value)