mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
hicli/html: preallocate space for html sanitization buffer
This commit is contained in:
parent
227ba474ef
commit
8a34618a70
2 changed files with 4 additions and 0 deletions
|
@ -505,9 +505,12 @@ func getCodeBlockLanguage(token html.Token) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
const builderPreallocBuffer = 100
|
||||
|
||||
func sanitizeAndLinkifyHTML(body string) (string, []id.ContentURI, error) {
|
||||
tz := html.NewTokenizer(strings.NewReader(body))
|
||||
var built strings.Builder
|
||||
built.Grow(len(body) + builderPreallocBuffer)
|
||||
var codeBlock *strings.Builder
|
||||
var codeBlockLanguage string
|
||||
var inlineImages []id.ContentURI
|
||||
|
|
|
@ -384,6 +384,7 @@ func (h *HiClient) calculateLocalContent(ctx context.Context, dbEvt *database.Ev
|
|||
}
|
||||
} else {
|
||||
var builder strings.Builder
|
||||
builder.Grow(len(content.Body) + builderPreallocBuffer)
|
||||
linkifyAndWriteBytes(&builder, []byte(content.Body))
|
||||
sanitizedHTML = builder.String()
|
||||
wasPlaintext = true
|
||||
|
|
Loading…
Add table
Reference in a new issue