-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(renderer): Use string instead of []byte internally (#625)
This uses strings.Builder to get more efficiency and reduce copies, but more importantly it gets rid of the need to pipe output through printf "%s" in templates, which makes them cleaner and nicer to work with. Fixes #619
- Loading branch information
Showing
38 changed files
with
355 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
package sgml | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
|
||
"github.com/bytesparadise/libasciidoc/pkg/types" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func (r *sgmlRenderer) renderBlankLine(ctx *Context, _ types.BlankLine) ([]byte, error) { | ||
func (r *sgmlRenderer) renderBlankLine(ctx *Context, _ types.BlankLine) (string, error) { | ||
if ctx.IncludeBlankLine { | ||
buf := &bytes.Buffer{} | ||
buf := &strings.Builder{} | ||
if err := r.blankLine.Execute(buf, nil); err != nil { | ||
return nil, err | ||
return "", err | ||
} | ||
log.Debug("rendering blank line") | ||
return buf.Bytes(), nil | ||
return buf.String(), nil | ||
} | ||
return []byte{}, nil | ||
return "", nil | ||
} | ||
|
||
func (r *sgmlRenderer) renderLineBreak() ([]byte, error) { | ||
buf := &bytes.Buffer{} | ||
func (r *sgmlRenderer) renderLineBreak() (string, error) { | ||
buf := &strings.Builder{} | ||
if err := r.lineBreak.Execute(buf, nil); err != nil { | ||
return nil, err | ||
return "", err | ||
} | ||
return buf.Bytes(), nil | ||
return buf.String(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.