mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
hugolib: Pre-allocate some slices
This commit is contained in:
parent
b32ffed6ab
commit
a9be687b81
2 changed files with 7 additions and 6 deletions
|
@ -142,9 +142,10 @@ func (p Pages) GroupBy(key string, order ...string) (PagesGroup, error) {
|
||||||
tmp.SetMapIndex(fv, reflect.Append(tmp.MapIndex(fv), ppv))
|
tmp.SetMapIndex(fv, reflect.Append(tmp.MapIndex(fv), ppv))
|
||||||
}
|
}
|
||||||
|
|
||||||
var r []PageGroup
|
sortedKeys := sortKeys(tmp.MapKeys(), direction)
|
||||||
for _, k := range sortKeys(tmp.MapKeys(), direction) {
|
r := make([]PageGroup, len(sortedKeys))
|
||||||
r = append(r, PageGroup{Key: k.Interface(), Pages: tmp.MapIndex(k).Interface().([]*Page)})
|
for i, k := range sortedKeys {
|
||||||
|
r[i] = PageGroup{Key: k.Interface(), Pages: tmp.MapIndex(k).Interface().([]*Page)}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r, nil
|
return r, nil
|
||||||
|
|
|
@ -76,10 +76,10 @@ func (c *PageCollections) refreshPageCaches() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var partitions []cache.Partition
|
partitions := make([]cache.Partition, len(allKindsInPages))
|
||||||
|
|
||||||
for _, kind := range allKindsInPages {
|
for i, kind := range allKindsInPages {
|
||||||
partitions = append(partitions, cache.Partition{Key: kind, Load: cacheLoader(kind)})
|
partitions[i] = cache.Partition{Key: kind, Load: cacheLoader(kind)}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.pageCache = cache.NewPartitionedLazyCache(partitions...)
|
c.pageCache = cache.NewPartitionedLazyCache(partitions...)
|
||||||
|
|
Loading…
Reference in a new issue