Title: [292693] trunk/Source/WebCore
Revision
292693
Author
cdu...@apple.com
Date
2022-04-10 18:32:25 -0700 (Sun, 10 Apr 2022)

Log Message

Update listMarkerTextForNodeAndPosition() to return a StringView instead of a String
https://bugs.webkit.org/show_bug.cgi?id=239022
<rdar://problem/91509602>

Reviewed by Darin Adler.

Update listMarkerTextForNodeAndPosition() to return a StringView instead of a String. listMarkerTextForNodeAndPosition()
has a StringView internally and none it its call sites actually need a String. The call sites either use StringBuilder
or want a NSString*. This avoids unnecessary String allocations.

* accessibility/AccessibilityObject.cpp:
(WebCore::listMarkerTextForNode):
(WebCore::AccessibilityObject::listMarkerTextForNodeAndPosition):
* accessibility/AccessibilityObject.h:
* accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
(AXAttributedStringAppendText):
(-[WebAccessibilityObjectWrapperBase contentForSimpleRange:attributed:]):
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292692 => 292693)


--- trunk/Source/WebCore/ChangeLog	2022-04-10 23:54:28 UTC (rev 292692)
+++ trunk/Source/WebCore/ChangeLog	2022-04-11 01:32:25 UTC (rev 292693)
@@ -1,5 +1,27 @@
 2022-04-10  Chris Dumez  <cdu...@apple.com>
 
+        Update listMarkerTextForNodeAndPosition() to return a StringView instead of a String
+        https://bugs.webkit.org/show_bug.cgi?id=239022
+        <rdar://problem/91509602>
+
+        Reviewed by Darin Adler.
+
+        Update listMarkerTextForNodeAndPosition() to return a StringView instead of a String. listMarkerTextForNodeAndPosition()
+        has a StringView internally and none it its call sites actually need a String. The call sites either use StringBuilder
+        or want a NSString*. This avoids unnecessary String allocations.
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::listMarkerTextForNode):
+        (WebCore::AccessibilityObject::listMarkerTextForNodeAndPosition):
+        * accessibility/AccessibilityObject.h:
+        * accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
+        (AXAttributedStringAppendText):
+        (-[WebAccessibilityObjectWrapperBase contentForSimpleRange:attributed:]):
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]):
+
+2022-04-10  Chris Dumez  <cdu...@apple.com>
+
         Avoid redundant calls to findHTTPHeaderName()
         https://bugs.webkit.org/show_bug.cgi?id=239021
 

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (292692 => 292693)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2022-04-10 23:54:28 UTC (rev 292692)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2022-04-11 01:32:25 UTC (rev 292693)
@@ -1440,20 +1440,20 @@
     return nullptr;
 }
 
-static String listMarkerTextForNode(Node* node)
+static StringView listMarkerTextForNode(Node* node)
 {
     RenderListItem* listItem = renderListItemContainerForNode(node);
     if (!listItem)
-        return String();
+        return { };
     
     // If this is in a list item, we need to manually add the text for the list marker
     // because a RenderListMarker does not have a Node equivalent and thus does not appear
     // when iterating text.
-    return listItem->markerTextWithSuffix().toString();
+    return listItem->markerTextWithSuffix();
 }
 
 // Returns the text associated with a list marker if this node is contained within a list item.
-String AccessibilityObject::listMarkerTextForNodeAndPosition(Node* node, const VisiblePosition& visiblePositionStart)
+StringView AccessibilityObject::listMarkerTextForNodeAndPosition(Node* node, const VisiblePosition& visiblePositionStart)
 {
     auto* listItem = renderListItemContainerForNode(node);
     if (!listItem)

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.h (292692 => 292693)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.h	2022-04-10 23:54:28 UTC (rev 292692)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.h	2022-04-11 01:32:25 UTC (rev 292693)
@@ -607,7 +607,7 @@
     String doAXStringForRange(const PlainTextRange&) const override { return String(); }
     IntRect doAXBoundsForRange(const PlainTextRange&) const override { return IntRect(); }
     IntRect doAXBoundsForRangeUsingCharacterOffset(const PlainTextRange&) const override { return IntRect(); }
-    static String listMarkerTextForNodeAndPosition(Node*, const VisiblePosition&);
+    static StringView listMarkerTextForNodeAndPosition(Node*, const VisiblePosition&);
 
     unsigned doAXLineForIndex(unsigned) override;
 

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm (292692 => 292693)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm	2022-04-10 23:54:28 UTC (rev 292692)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm	2022-04-11 01:32:25 UTC (rev 292693)
@@ -671,7 +671,7 @@
         [attrString addAttribute:UIAccessibilityTextAttributeContext value:UIAccessibilityTextualContextSourceCode range:range];
 }
 
-static void AXAttributedStringAppendText(NSMutableAttributedString* attrString, Node* node, NSString *text)
+static void AXAttributedStringAppendText(NSMutableAttributedString* attrString, Node* node, StringView text)
 {
     // skip invisible text
     if (!node->renderer())
@@ -678,10 +678,10 @@
         return;
 
     // easier to calculate the range before appending the string
-    NSRange attrStringRange = NSMakeRange([attrString length], [text length]);
+    NSRange attrStringRange = NSMakeRange([attrString length], text.length());
 
     // append the string from this node
-    [[attrString mutableString] appendString:text];
+    [[attrString mutableString] appendString:text.createNSStringWithoutCopying().get()];
 
     // set new attributes
     AXAttributeStringSetStyle(attrString, node->renderer(), attrStringRange);
@@ -757,13 +757,13 @@
                 if (addObjectWrapperToArray(headingObject, array.get()))
                     continue;
 
-                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, makeContainerOffsetPosition(it.range().start));
+                StringView listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, makeContainerOffsetPosition(it.range().start));
                 if (!listMarkerText.isEmpty())
-                    [array addObject:listMarkerText];
+                    [array addObject:listMarkerText.createNSString().get()];
                 // There was not an element representation, so just return the text.
                 [array addObject:it.text().createNSString().get()];
             } else {
-                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, makeContainerOffsetPosition(it.range().start));
+                StringView listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, makeContainerOffsetPosition(it.range().start));
                 if (!listMarkerText.isEmpty()) {
                     auto attrString = adoptNS([[NSMutableAttributedString alloc] init]);
                     AXAttributedStringAppendText(attrString.get(), &node, listMarkerText);
@@ -771,7 +771,7 @@
                 }
 
                 auto attrString = adoptNS([[NSMutableAttributedString alloc] init]);
-                AXAttributedStringAppendText(attrString.get(), &node, it.text().createNSStringWithoutCopying().get());
+                AXAttributedStringAppendText(attrString.get(), &node, it.text());
                 [array addObject:attrString.get()];
             }
         } else {

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (292692 => 292693)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2022-04-10 23:54:28 UTC (rev 292692)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2022-04-11 01:32:25 UTC (rev 292693)
@@ -1055,7 +1055,7 @@
             // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
             if (it.text().length()) {
                 // Add the text of the list marker item if necessary.
-                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, makeContainerOffsetPosition(it.range().start));
+                StringView listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, makeContainerOffsetPosition(it.range().start));
                 if (!listMarkerText.isEmpty())
                     AXAttributedStringAppendText(attrString.get(), &node, listMarkerText, spellCheck);
                 AXAttributedStringAppendText(attrString.get(), &node, it.text(), spellCheck);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to