shithub: hugo

Download patch

ref: 3663828f5eefc5cda8ebc0d3077d3c3fb90066c0
parent: 77c60a3440806067109347d04eb5368b65ea0fe8
author: Bjørn Erik Pedersen <[email protected]>
date: Sun Jul 12 07:28:19 EDT 2015

Optimize RuneCount

Do not create it unless used.

See #1266

--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -68,6 +68,7 @@
 	plainWords          []string
 	plainRuneCount      int
 	plainInit           sync.Once
+	plainSecondaryInit  sync.Once
 	renderingConfig     *helpers.Blackfriday
 	renderingConfigInit sync.Once
 	PageMeta
@@ -111,7 +112,7 @@
 
 // RuneCount returns the rune count, excluding any whitespace, of the plain content.
 func (p *Page) RuneCount() int {
-	p.initPlain()
+	p.initPlainSecondary()
 	return p.plainRuneCount
 }
 
@@ -119,6 +120,13 @@
 	p.plainInit.Do(func() {
 		p.plain = helpers.StripHTML(string(p.Content))
 		p.plainWords = strings.Fields(p.plain)
+		return
+	})
+}
+
+func (p *Page) initPlainSecondary() {
+	p.plainSecondaryInit.Do(func() {
+		p.initPlain()
 		runeCount := 0
 		for _, r := range p.plain {
 			if !helpers.IsWhitespace(r) {