Skip to content

Commit a9be687

Browse files
committed
hugolib: Pre-allocate some slices
1 parent b32ffed commit a9be687

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

‎hugolib/pageGroup.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ func (p Pages) GroupBy(key string, order ...string) (PagesGroup, error) {
142142
tmp.SetMapIndex(fv, reflect.Append(tmp.MapIndex(fv), ppv))
143143
}
144144

145-
var r []PageGroup
146-
for _, k := range sortKeys(tmp.MapKeys(), direction) {
147-
r = append(r, PageGroup{Key: k.Interface(), Pages: tmp.MapIndex(k).Interface().([]*Page)})
145+
sortedKeys := sortKeys(tmp.MapKeys(), direction)
146+
r := make([]PageGroup, len(sortedKeys))
147+
for i, k := range sortedKeys {
148+
r[i] = PageGroup{Key: k.Interface(), Pages: tmp.MapIndex(k).Interface().([]*Page)}
148149
}
149150

150151
return r, nil

‎hugolib/page_collections.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ func (c *PageCollections) refreshPageCaches() {
7676
}
7777
}
7878

79-
var partitions []cache.Partition
79+
partitions := make([]cache.Partition, len(allKindsInPages))
8080

81-
for _, kind := range allKindsInPages {
82-
partitions = append(partitions, cache.Partition{Key: kind, Load: cacheLoader(kind)})
81+
for i, kind := range allKindsInPages {
82+
partitions[i] = cache.Partition{Key: kind, Load: cacheLoader(kind)}
8383
}
8484

8585
c.pageCache = cache.NewPartitionedLazyCache(partitions...)

0 commit comments

Comments
 (0)