From a675dd7fafb3887f5cb6905aa3497181a134081a Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Mon, 3 Apr 2023 05:19:28 -0700 Subject: [PATCH] Only create NSAttributedString if NSTextStorage is nil (#36773) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36773 Changelog: [internal] Do not construct `NSAttributedString` if `NSTextStorage` exists. Creating `NSAttributedString` is expensive and it isn't needed to measure text if `NSTextStorage` `exists` Reviewed By: cipolleschi Differential Revision: D44620292 fbshipit-source-id: 0827c514e40fcbd9626d2b7d7b6d28a3332d9aa1 --- .../textlayoutmanager/RCTTextLayoutManager.mm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm index e486049ad4b..35aa4119b81 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm @@ -64,10 +64,14 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(EllipsizeMode ellipsi layoutConstraints:(LayoutConstraints)layoutConstraints textStorage:(NSTextStorage *_Nullable)textStorage { - return [self measureNSAttributedString:[self _nsAttributedStringFromAttributedString:attributedString] - paragraphAttributes:paragraphAttributes - layoutConstraints:layoutConstraints - textStorage:textStorage]; + if (textStorage) { + return [self _measureTextStorage:textStorage]; + } else { + return [self measureNSAttributedString:[self _nsAttributedStringFromAttributedString:attributedString] + paragraphAttributes:paragraphAttributes + layoutConstraints:layoutConstraints + textStorage:nil]; + } } - (void)drawAttributedString:(AttributedString)attributedString