From 1ee7ab9405a06f3b1eb083d7d8a9ff5feea53006 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 26 Dec 2023 12:02:38 -0500 Subject: [PATCH] Avoid dictionary lookups when setting paragraph style --- Sources/HTMLStreamer/AttributedStringConverter.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/HTMLStreamer/AttributedStringConverter.swift b/Sources/HTMLStreamer/AttributedStringConverter.swift index 4664e53..a287c4d 100644 --- a/Sources/HTMLStreamer/AttributedStringConverter.swift +++ b/Sources/HTMLStreamer/AttributedStringConverter.swift @@ -257,6 +257,7 @@ public struct AttributedStringConverter { } var attributes = [NSAttributedString.Key: Any]() + var paragraphStyle = configuration.paragraphStyle var currentFontTraits: FontTrait = [] for style in styleStack { switch style { @@ -273,19 +274,17 @@ public struct AttributedStringConverter { case .strikethrough: attributes[.strikethroughStyle] = NSUnderlineStyle.single.rawValue case .blockquote: - attributes[.paragraphStyle] = blockquoteParagraphStyle + paragraphStyle = blockquoteParagraphStyle currentFontTraits.insert(.italic) case .orderedList, .unorderedList: - attributes[.paragraphStyle] = listParagraphStyle + paragraphStyle = listParagraphStyle } } attributes[.font] = getFont(traits: currentFontTraits) attributes[.foregroundColor] = configuration.color - if !attributes.keys.contains(.paragraphStyle) { - attributes[.paragraphStyle] = configuration.paragraphStyle - } + attributes[.paragraphStyle] = paragraphStyle str.append(NSAttributedString(string: currentRun, attributes: attributes)) currentRun = ""