Skip to content

Commit

Permalink
feat: pool byte buffers (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerdav authored Nov 10, 2022
1 parent 5787320 commit 3b33e9c
Show file tree
Hide file tree
Showing 28 changed files with 120 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.19

- name: Test
run: go test -v ./...
5 changes: 3 additions & 2 deletions benchmarks/templ/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions cmd/templ/generatecmd/sourcemapvisualisation_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 14 additions & 7 deletions example/posts_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,12 @@ func (g *generator) writeTemplate(t parser.HTMLTemplate) error {
}
{
indentLevel++
// templBuffer := new(bytes.Buffer)
if _, err = g.w.WriteIndent(indentLevel, "templBuffer = new(bytes.Buffer)\n"); err != nil {
// templBuffer = templ.GetBuffer()
if _, err = g.w.WriteIndent(indentLevel, "templBuffer = templ.GetBuffer()\n"); err != nil {
return err
}
// defer templ.ReleaseBuffer(templBuffer)
if _, err = g.w.WriteIndent(indentLevel, "defer templ.ReleaseBuffer(templBuffer)\n"); err != nil {
return err
}
indentLevel--
Expand Down Expand Up @@ -336,7 +340,7 @@ func (g *generator) writeTemplate(t parser.HTMLTemplate) error {
}
{
indentLevel++
// _, err = io.Copy(w, buf)
// _, err = io.Copy(w, templBuffer)
if _, err = g.w.WriteIndent(indentLevel, "_, err = io.Copy(w, templBuffer)\n"); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion generator/test-a-href/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-attribute-escaping/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions generator/test-call/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions generator/test-css-usage/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-doctype/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-for/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-html/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-if/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-ifelse/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions generator/test-raw-elements/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions generator/test-script-usage/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-string/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-switch/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-switchdefault/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions generator/test-templ-element/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions generator/test-text-whitespace/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-text/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion generator/test-void/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3b33e9c

Please sign in to comment.