Optimize word collection loop
This commit is contained in:
@@ -343,25 +343,21 @@ func (p *ScrollerPage) loadProclamations() error {
|
||||
}
|
||||
|
||||
// Build word list from selected, available proclamations
|
||||
// For each proclamation in proclamations
|
||||
// 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
|
||||
defaultWords := strings.Fields(defaultProclamation.Content)
|
||||
|
||||
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)
|
||||
words := strings.Fields(proclamation.Content)
|
||||
p.words = append(p.words, words...)
|
||||
count += 1
|
||||
batch = append(batch, words...)
|
||||
}
|
||||
logger.Debug("Adding %s", defaultProclamation.Name)
|
||||
defaultWords := strings.Fields(defaultProclamation.Content)
|
||||
p.words = append(p.words, defaultWords...)
|
||||
count = 0
|
||||
batch = append(batch, defaultWords...)
|
||||
|
||||
p.words = append(p.words, batch...)
|
||||
}
|
||||
|
||||
if len(p.words) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user