diff options
author | Gabe Cook | 2025-03-03 04:48:16 -0600 |
---|---|---|
committer | GitHub | 2025-03-03 11:48:16 +0100 |
commit | ac5c615468e972376d23447de91eb1ea39a315bb (patch) | |
tree | ec2fff0b5d0b6096a921fec7157aba7d82dbaf84 /gomponents.go | |
parent | 0368e39c137c7f1ab37c84c0787fd6cc9da0c34b (diff) | |
download | gomponents-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 'gomponents.go')
-rw-r--r-- | gomponents.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gomponents.go b/gomponents.go index 735ad00..ad9c2cd 100644 --- a/gomponents.go +++ b/gomponents.go @@ -250,7 +250,7 @@ func Rawf(format string, a ...interface{}) Node { // Map a slice of anything to a [Group] (which is just a slice of [Node]-s). func Map[T any](ts []T, cb func(T) Node) Group { - var nodes []Node + nodes := make([]Node, 0, len(ts)) for _, t := range ts { nodes = append(nodes, cb(t)) } |