... Currently the only temporary attributes recognized are those that do not affect layout (colors, underlines, and so on). func addAttributes(_:range:) I am dogco w. I am dogcow. NSTextLayoutManagerͷrendering attributesʹ૬ Temporary attributes NSLayoutManager Attributes NSTextStorage
{ layoutManager.addTemporaryAttributes(attributes, forCharacterRange: range) } for range in ranges { textStorage.addAttribute(attributes, range: range) } ? s 3.35 s textStorage.beginEditing() for range in ranges { textStorage.addAttribute(attributes, range: range) } textStorage.endEditing() 4.46 s Temporary attributes NSLayoutManager Attributes NSTextStorage
range highlightRange: NSRange, theme: Theme) { layoutManager.removeTemporaryAttribute(.foregroundColor, forCharacterRange: highlightRange) for type in SyntaxType.allCases { guard let ranges = highlights[type]?.compactMap({ $0.intersection(highlightRange) }), !ranges.isEmpty else { continue } let color = theme.style(for: type).color for range in ranges { layoutManager.addTemporaryAttribute(.foregroundColor, value: color, forCharacterRange: range) } } } 3.33 s 3.35 s – NSLayoutManager.invalidateDisplay(forCharacterRange:) – [NSMutableRLEArray replaceObjectsInRange:withObject:length:] – [__NSDictonaryM mutableCopyWithZone:] 2.58 s 0.73 s 0.005 s
charRange: NSRange) Summary Invalidates display for the specified character range. Discussion Parts of the range that are not laid out are remembered and redisplayed later when the layout is available. Does not actually cause layout. fi fi Temporary attributes NSLayoutManager Attributes NSTextStorage fi fi
range highlightRange: NSRange, theme: Theme) { layoutManager.removeTemporaryAttribute(.foregroundColor, forCharacterRange: highlightRange) for type in SyntaxType.allCases { guard let ranges = highlights[type]?.compactMap({ $0.intersection(highlightRange) }), !ranges.isEmpty else { continue } let color = theme.style(for: type).color for range in ranges { layoutManager.addTemporaryAttribute(.foregroundColor, value: color, forCharacterRange: range) } } } 3.33 s 3.35 s – NSLayoutManager.invalidateDisplay(forCharacterRange:) – [NSMutableRLEArray replaceObjectsInRange:withObject:length:] – [__NSDictonaryM mutableCopyWithZone:] 2.58 s 0.73 s 0.005 s
range highlightRange: NSRange, theme: Theme) { layoutManager.groupTemporaryAttributesUpdate(in: highlightRange) { layoutManager.removeTemporaryAttribute(.foregroundColor, forCharacterRange: highlightRange) for type in SyntaxType.allCases { guard let ranges = highlights[type]?.compactMap({ $0.intersection(highlightRange) }), !ranges.isEmpty else { continue } let color = theme.style(for: type).color for range in ranges { layoutManager.addTemporaryAttribute(.foregroundColor, value: color, forCharacterRange: range) } } } } 0.736 s 0.76 s – NSLayoutManager.invalidateDisplay(forCharacterRange:) – [NSMutableRLEArray replaceObjectsInRange:withObject:length:] – [__NSDictonaryM mutableCopyWithZone:] 2.58 s 0.73 s 0.005 s
range highlightRange: NSRange, theme: Theme) { layoutManager.groupTemporaryAttributesUpdate(in: highlightRange) { layoutManager.removeTemporaryAttribute(.foregroundColor, forCharacterRange: highlightRange) for type in SyntaxType.allCases { guard let ranges = highlights[type]?.compactMap({ $0.intersection(highlightRange) }), !ranges.isEmpty else { continue } let color = theme.style(for: type).color for range in ranges { layoutManager.addTemporaryAttribute(.foregroundColor, value: color, forCharacterRange: range) } } } } 0.736 s 0.76 s – [NSMutableRLEArray replaceObjectsInRange:withObject:length:] – [__NSDictonaryM mutableCopyWithZone:] 0.73 s 0.005 s
range highlightRange: NSRange, theme: Theme) { layoutManager.groupTemporaryAttributesUpdate(in: highlightRange) { layoutManager.removeTemporaryAttribute(.foregroundColor, forCharacterRange: highlightRange) for type in SyntaxType.allCases { guard let ranges = highlights[type]?.compactMap({ $0.intersection(highlightRange) }), !ranges.isEmpty else { continue } let color = theme.style(for: type).color for range in ranges { layoutManager.addTemporaryAttribute(.foregroundColor, value: color, forCharacterRange: range) } } } } 0.736 s 0.76 s – [NSMutableRLEArray replaceObjectsInRange:withObject:length:] – [__NSDictonaryM mutableCopyWithZone:] 0.73 s 0.005 s