From eb5bd0942bda4939b42eab188e1d62357e3058ba Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Thu, 13 Sep 2018 11:06:12 -0700 Subject: [PATCH] Don't copy container during ASTextNode2 layout (#1115) --- CHANGELOG.md | 1 + Source/ASTextNode2.mm | 11 ++--------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9752ddbda..731724ca30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - Renamed `accessibleElements` to `accessibilityElements` and removed the re-definition of the property in ASDisplayView. [Jia Wern Lim](https://github.com/jiawernlim) - Remove double scaling of lineHeightMultiple & paragraphSpacing attributes in ASTextKitFontSizeAdjuster. [Eric Jensen](https://github.com/ejensen) - Add a delegate callback for when the framework has initialized. [Adlai Holler](https://github.com/Adlai-Holler) +- Improve TextNode2 by skipping an unneeded copy during measurement. [Adlai Holler](https://github.com/Adlai-Holler) ## 2.7 - Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877) diff --git a/Source/ASTextNode2.mm b/Source/ASTextNode2.mm index 1cdb77f1ab..813326bddf 100644 --- a/Source/ASTextNode2.mm +++ b/Source/ASTextNode2.mm @@ -232,19 +232,12 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ]; ASLockScopeSelf(); - ASTextContainer *container; - if (!CGSizeEqualToSize(container.size, constrainedSize)) { - container = [_textContainer copy]; - container.size = constrainedSize; - [container makeImmutable]; - } else { - container = _textContainer; - } + _textContainer.size = constrainedSize; [self _ensureTruncationText]; NSMutableAttributedString *mutableText = [_attributedText mutableCopy]; [self prepareAttributedString:mutableText]; - ASTextLayout *layout = [ASTextNode2 compatibleLayoutWithContainer:container text:mutableText]; + ASTextLayout *layout = [ASTextNode2 compatibleLayoutWithContainer:_textContainer text:mutableText]; return layout.textBoundingSize; }