Speed up strippingHTML dramatically by calling reserveCharacters with maxCharacters when possible, which is generally much less than the count of preflight characters.

This commit is contained in:
Brent Simmons 2024-09-29 10:53:56 -07:00
parent 75e525380b
commit 3b17e77358

View File

@ -223,7 +223,12 @@ public extension String {
preflight = preflight.removingTagAndContents("style") preflight = preflight.removingTagAndContents("style")
var s = String() var s = String()
s.reserveCapacity(preflight.count) if let maxCharacters {
s.reserveCapacity(maxCharacters)
}
else {
s.reserveCapacity(preflight.count)
}
var lastCharacterWasSpace = false var lastCharacterWasSpace = false
var charactersAdded = 0 var charactersAdded = 0
var level = 0 var level = 0