shithub: hugo

Download patch

ref: 5441fc5dfc056a4e4dfd34ca16f0928e482b4c29
parent: 2f2297bdb324471be3976809dfc545e211b4db08
author: spf13 <[email protected]>
date: Fri Jan 30 06:25:54 EST 2015

template render with BBP

--- a/tpl/template.go
+++ b/tpl/template.go
@@ -17,11 +17,6 @@
 	"bytes"
 	"errors"
 	"fmt"
-	"github.com/eknkc/amber"
-	"github.com/spf13/cast"
-	"github.com/spf13/hugo/helpers"
-	jww "github.com/spf13/jwalterweatherman"
-	"github.com/yosssi/ace"
 	"html"
 	"html/template"
 	"io"
@@ -32,6 +27,13 @@
 	"sort"
 	"strconv"
 	"strings"
+
+	"github.com/eknkc/amber"
+	"github.com/spf13/cast"
+	bp "github.com/spf13/hugo/bufferpool"
+	"github.com/spf13/hugo/helpers"
+	jww "github.com/spf13/jwalterweatherman"
+	"github.com/yosssi/ace"
 )
 
 var localTemplates *template.Template
@@ -1101,8 +1103,7 @@
 	return ExecuteTemplateToHTML(context, "partials/"+name, "theme/partials/"+name)
 }
 
-func ExecuteTemplate(context interface{}, layouts ...string) *bytes.Buffer {
-	buffer := new(bytes.Buffer)
+func ExecuteTemplate(context interface{}, buffer *bytes.Buffer, layouts ...string) {
 	worked := false
 	for _, layout := range layouts {
 
@@ -1125,13 +1126,13 @@
 		jww.ERROR.Println("Unable to render", layouts)
 		jww.ERROR.Println("Expecting to find a template in either the theme/layouts or /layouts in one of the following relative locations", layouts)
 	}
-
-	return buffer
 }
 
 func ExecuteTemplateToHTML(context interface{}, layouts ...string) template.HTML {
-	b := ExecuteTemplate(context, layouts...)
-	return template.HTML(string(b.Bytes()))
+	b := bp.GetBuffer()
+	defer bp.PutBuffer(b)
+	ExecuteTemplate(context, b, layouts...)
+	return template.HTML(b.String())
 }
 
 func (t *GoHtmlTemplate) LoadEmbedded() {