about summary refs log tree commit diff stats
path: root/components
diff options
context:
space:
mode:
authorGabe Cook2025-03-03 04:48:16 -0600
committerGitHub2025-03-03 11:48:16 +0100
commitac5c615468e972376d23447de91eb1ea39a315bb (patch)
treeec2fff0b5d0b6096a921fec7157aba7d82dbaf84 /components
parent0368e39c137c7f1ab37c84c0787fd6cc9da0c34b (diff)
downloadgomponents-ac5c615468e972376d23447de91eb1ea39a315bb.tar.lz
gomponents-ac5c615468e972376d23447de91eb1ea39a315bb.tar.zst
gomponents-ac5c615468e972376d23447de91eb1ea39a315bb.zip
Set slice capacity based on input in `Map` and `Classes.Render` (#243)
Hey! I just discovered this repo and I love being able to write
templates while still having compile-time checks.

I was looking through the code and noticed slices aren't currently
preallocated in `Map()` and `Classes.Render()`. Preallocating will
improve performance since the resulting slice won't have to be grown
dynamically during the append loop.
Diffstat (limited to 'components')
-rw-r--r--components/components.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/components/components.go b/components/components.go
index 122882f..d37ccf4 100644
--- a/components/components.go
+++ b/components/components.go
@@ -44,7 +44,7 @@ type Classes map[string]bool
 
 // Render satisfies [g.Node].
 func (c Classes) Render(w io.Writer) error {
-	var included []string
+	included := make([]string, 0, len(c))
 	for c, include := range c {
 		if include {
 			included = append(included, c)