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 ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const builderPreallocBuffer = 100
|
||||||
|
|
||||||
func sanitizeAndLinkifyHTML(body string) (string, []id.ContentURI, error) {
|
func sanitizeAndLinkifyHTML(body string) (string, []id.ContentURI, error) {
|
||||||
tz := html.NewTokenizer(strings.NewReader(body))
|
tz := html.NewTokenizer(strings.NewReader(body))
|
||||||
var built strings.Builder
|
var built strings.Builder
|
||||||
|
built.Grow(len(body) + builderPreallocBuffer)
|
||||||
var codeBlock *strings.Builder
|
var codeBlock *strings.Builder
|
||||||
var codeBlockLanguage string
|
var codeBlockLanguage string
|
||||||
var inlineImages []id.ContentURI
|
var inlineImages []id.ContentURI
|
||||||
|
|
|
@ -384,6 +384,7 @@ func (h *HiClient) calculateLocalContent(ctx context.Context, dbEvt *database.Ev
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var builder strings.Builder
|
var builder strings.Builder
|
||||||
|
builder.Grow(len(content.Body) + builderPreallocBuffer)
|
||||||
linkifyAndWriteBytes(&builder, []byte(content.Body))
|
linkifyAndWriteBytes(&builder, []byte(content.Body))
|
||||||
sanitizedHTML = builder.String()
|
sanitizedHTML = builder.String()
|
||||||
wasPlaintext = true
|
wasPlaintext = true
|
||||||
|
|
Loading…
Add table
Reference in a new issue