Avoid calling strings.Fields multiple times with same content

This should be a relief for big sites.
This commit is contained in:
bep
2015-02-05 00:38:50 +01:00
parent 11a19e0760
commit f8704c1bf2
2 changed files with 22 additions and 9 deletions

View File

@@ -275,8 +275,7 @@ func TruncateWords(s string, max int) string {
// TruncateWordsToWholeSentence takes content and an int
// and returns entire sentences from content, delimited by the int.
func TruncateWordsToWholeSentence(s string, max int) string {
words := strings.Fields(s)
func TruncateWordsToWholeSentence(words []string, max int) string {
if max > len(words) {
return strings.Join(words, " ")
}