From 3b17e773589383bc34e26f01f38e025ab5cd6cd5 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 29 Sep 2024 10:53:56 -0700 Subject: [PATCH] Speed up strippingHTML dramatically by calling reserveCharacters with maxCharacters when possible, which is generally much less than the count of preflight characters. --- .../Sources/FoundationExtras/String+RSCore.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Modules/FoundationExtras/Sources/FoundationExtras/String+RSCore.swift b/Modules/FoundationExtras/Sources/FoundationExtras/String+RSCore.swift index 3d0c141d3..ff89475ca 100644 --- a/Modules/FoundationExtras/Sources/FoundationExtras/String+RSCore.swift +++ b/Modules/FoundationExtras/Sources/FoundationExtras/String+RSCore.swift @@ -223,7 +223,12 @@ public extension String { preflight = preflight.removingTagAndContents("style") var s = String() - s.reserveCapacity(preflight.count) + if let maxCharacters { + s.reserveCapacity(maxCharacters) + } + else { + s.reserveCapacity(preflight.count) + } var lastCharacterWasSpace = false var charactersAdded = 0 var level = 0