summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-27 09:34:16 +0300
committerPaul Buetow <paul@buetow.org>2026-04-27 09:34:16 +0300
commitfe142ba40f1866dd9e4855e8d6a00857e6f90bec (patch)
tree84a0da8e0967947c913118edefb6d2b6767322c9 /internal
parent1cfca79184e8cc2214d971c98feb1306bc801e0c (diff)
+code-quality Add slice capacity pre-allocation in loadAllPosts and paginate
- loadAllPosts: pre-allocate posts slice with capacity len(entries) since each directory entry may become a post. - paginate: pre-allocate pages slice with capacity (len(posts)+pageSize-1)/pageSize. The concat function no longer exists in the codebase (removed when theme sound data was moved to embedded JSON files in commit 06dd860).
Diffstat (limited to 'internal')
-rw-r--r--internal/generator/generator.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/internal/generator/generator.go b/internal/generator/generator.go
index 1bdd7c7..533a771 100644
--- a/internal/generator/generator.go
+++ b/internal/generator/generator.go
@@ -124,7 +124,7 @@ func loadAllPosts(outputDir string) ([]*post.Post, error) {
return nil, fmt.Errorf("read posts dir: %w", err)
}
- var posts []*post.Post
+ posts := make([]*post.Post, 0, len(entries))
for _, entry := range entries {
if !entry.IsDir() {
@@ -144,7 +144,8 @@ func loadAllPosts(outputDir string) ([]*post.Post, error) {
// paginate splits posts into chunks of size pageSize.
func paginate(posts []*post.Post, pageSize int) [][]*post.Post {
- var pages [][]*post.Post
+ pageCount := (len(posts) + pageSize - 1) / pageSize
+ pages := make([][]*post.Post, 0, pageCount)
for i := 0; i < len(posts); i += pageSize {
end := i + pageSize