Skip to content

Commit

Permalink
Update RenderText::text() to return a String instead of a StringImpl
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268918

Reviewed by Alan Baradlay.

Update RenderText::text() to return a String instead of a StringImpl. It is safe
 to deal with Strings than with StringImpl pointers directly. There is also zero
 performance difference on Speedometer 2 & 3.

* Source/WebCore/editing/TextIterator.cpp:
(WebCore::collapsedSpaceLength):
* Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp:
(WebCore::LayoutIntegration::BoxTree::createLayoutBox):
(WebCore::LayoutIntegration::BoxTree::updateContent):
* Source/WebCore/rendering/RenderText.h:
(WebCore::RenderText::text const):

Canonical link: https://commits.webkit.org/274220@main
  • Loading branch information
cdumez committed Feb 7, 2024
1 parent 0c1bf2e commit c3d587a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/editing/TextIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ static bool shouldEmitExtraNewlineForNode(Node& node)

static int collapsedSpaceLength(RenderText& renderer, int textEnd)
{
StringImpl& text = renderer.text();
auto text = renderer.text();
unsigned length = text.length();
for (unsigned i = textEnd; i < length; ++i) {
if (!renderer.style().isCollapsibleWhiteSpace(text[i]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ UniqueRef<Layout::Box> BoxTree::createLayoutBox(RenderObject& renderer)
auto isCombinedText = is<RenderCombineText>(textRenderer) && downcast<RenderCombineText>(textRenderer).isCombined();
auto text = style.textSecurity() == TextSecurity::None
? (isCombinedText ? textRenderer.originalText() : textRenderer.text())
: RenderBlock::updateSecurityDiscCharacters(style, isCombinedText ? textRenderer.originalText() : textRenderer.text());
: RenderBlock::updateSecurityDiscCharacters(style, isCombinedText ? textRenderer.originalText() : String { textRenderer.text() });

auto canUseSimpleFontCodePath = textRenderer.canUseSimpleFontCodePath();
auto canUseSimplifiedTextMeasuring = textRenderer.canUseSimplifiedTextMeasuring();
Expand Down Expand Up @@ -295,7 +295,7 @@ void BoxTree::updateContent(const RenderText& textRenderer)
auto& inlineTextBox = downcast<Layout::InlineTextBox>(layoutBoxForRenderer(textRenderer));
auto& style = inlineTextBox.style();
auto isCombinedText = is<RenderCombineText>(textRenderer) && downcast<RenderCombineText>(textRenderer).isCombined();
auto text = style.textSecurity() == TextSecurity::None ? (isCombinedText ? textRenderer.originalText() : textRenderer.text()) : RenderBlock::updateSecurityDiscCharacters(style, isCombinedText ? textRenderer.originalText() : textRenderer.text());
auto text = style.textSecurity() == TextSecurity::None ? (isCombinedText ? textRenderer.originalText() : String { textRenderer.text() }) : RenderBlock::updateSecurityDiscCharacters(style, isCombinedText ? textRenderer.originalText() : String { textRenderer.text() });
auto contentCharacteristic = OptionSet<Layout::InlineTextBox::ContentCharacteristic> { };
if (textRenderer.canUseSimpleFontCodePath())
contentCharacteristic.add(Layout::InlineTextBox::ContentCharacteristic::CanUseSimpledFontCodepath);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/RenderText.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RenderText : public RenderObject {
void attachTextBox(LegacyInlineTextBox& box) { m_lineBoxes.attach(box); }
void removeTextBox(LegacyInlineTextBox& box) { m_lineBoxes.remove(box); }

StringImpl& text() const { return *m_text.impl(); } // Since m_text can never be null, returning this type means callers won't null check.
const String& text() const { return m_text; }
String textWithoutConvertingBackslashToYenSymbol() const;

LegacyInlineTextBox* createInlineTextBox() { return m_lineBoxes.createAndAppendLineBox(*this); }
Expand Down

0 comments on commit c3d587a

Please sign in to comment.