Optimize word collection loop

This commit is contained in:
NeilClack
2026-04-23 17:30:33 -05:00
parent dd069e9345
commit cfd67f3545
+11 -15
View File
@@ -343,25 +343,21 @@ func (p *ScrollerPage) loadProclamations() error {
} }
// Build word list from selected, available proclamations // Build word list from selected, available proclamations
// For each proclamation in proclamations defaultWords := strings.Fields(defaultProclamation.Content)
// until count reaches 10
// add the words into the world list
// update count
// when the count reaches 10
// insert the defaultProclamation
// reset the count to 0
var count int = 0
for _, proclamation := range proclamations { for _, proclamation := range proclamations {
for count < 10 { words := strings.Fields(proclamation.Content)
// Pre-allocate: 10x proclamation words + 1x default words
batch := make([]string, 0, len(words)*10+len(defaultWords))
for range 10 {
logger.Debug("Adding %s", proclamation.Name) logger.Debug("Adding %s", proclamation.Name)
words := strings.Fields(proclamation.Content) batch = append(batch, words...)
p.words = append(p.words, words...)
count += 1
} }
logger.Debug("Adding %s", defaultProclamation.Name) logger.Debug("Adding %s", defaultProclamation.Name)
defaultWords := strings.Fields(defaultProclamation.Content) batch = append(batch, defaultWords...)
p.words = append(p.words, defaultWords...)
count = 0 p.words = append(p.words, batch...)
} }
if len(p.words) == 0 { if len(p.words) == 0 {