Skip to content

Commit f6b81e3

Browse files
committed
[LFC][Integration] Use inline iterator in CompositeEditCommand::deleteInsignificantText
https://bugs.webkit.org/show_bug.cgi?id=219155 Reviewed by Zalan Bujtas. Reduce direct InlineBox access. * editing/CompositeEditCommand.cpp: (WebCore::CompositeEditCommand::deleteInsignificantText): Canonical link: https://commits.webkit.org/231770@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270029 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 79eb7da commit f6b81e3

2 files changed

Lines changed: 22 additions & 25 deletions

File tree

Source/WebCore/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2020-11-19 Antti Koivisto <antti@apple.com>
2+
3+
[LFC][Integration] Use inline iterator in CompositeEditCommand::deleteInsignificantText
4+
https://bugs.webkit.org/show_bug.cgi?id=219155
5+
6+
Reviewed by Zalan Bujtas.
7+
8+
Reduce direct InlineBox access.
9+
10+
* editing/CompositeEditCommand.cpp:
11+
(WebCore::CompositeEditCommand::deleteInsignificantText):
12+
113
2020-11-19 Zalan Bujtas <zalan@apple.com>
214

315
[LFC][Integration] Disable non-text content with floats

Source/WebCore/editing/CompositeEditCommand.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "InsertNodeBeforeCommand.h"
5454
#include "InsertParagraphSeparatorCommand.h"
5555
#include "InsertTextCommand.h"
56+
#include "LayoutIntegrationRunIterator.h"
5657
#include "MergeIdenticalElementsCommand.h"
5758
#include "NodeTraversal.h"
5859
#include "RemoveNodeCommand.h"
@@ -981,20 +982,8 @@ void CompositeEditCommand::deleteInsignificantText(Text& textNode, unsigned star
981982
if (!textRenderer)
982983
return;
983984

984-
Vector<InlineTextBox*> sortedTextBoxes;
985-
size_t sortedTextBoxesPosition = 0;
986-
987-
textRenderer->ensureLineBoxes();
988-
for (InlineTextBox* textBox = textRenderer->firstTextBox(); textBox; textBox = textBox->nextTextBox())
989-
sortedTextBoxes.append(textBox);
990-
991-
// If there is mixed directionality text, the boxes can be out of order,
992-
// (like Arabic with embedded LTR), so sort them first.
993-
if (textRenderer->containsReversedText())
994-
std::sort(sortedTextBoxes.begin(), sortedTextBoxes.end(), InlineTextBox::compareByStart);
995-
InlineTextBox* box = sortedTextBoxes.isEmpty() ? 0 : sortedTextBoxes[sortedTextBoxesPosition];
996-
997-
if (!box) {
985+
auto run = LayoutIntegration::firstTextRunInTextOrderFor(*textRenderer);
986+
if (!run) {
998987
// whole text node is empty
999988
removeNode(textNode);
1000989
return;
@@ -1005,18 +994,18 @@ void CompositeEditCommand::deleteInsignificantText(Text& textNode, unsigned star
1005994
return;
1006995

1007996
unsigned removed = 0;
1008-
InlineTextBox* prevBox = nullptr;
997+
LayoutIntegration::TextRunIterator previousRun;
1009998
String str;
1010999

10111000
// This loop structure works to process all gaps preceding a box,
10121001
// and also will look at the gap after the last box.
1013-
while (prevBox || box) {
1014-
unsigned gapStart = prevBox ? prevBox->start() + prevBox->len() : 0;
1002+
while (previousRun || run) {
1003+
unsigned gapStart = previousRun ? previousRun->end() : 0;
10151004
if (end < gapStart)
10161005
// No more chance for any intersections
10171006
break;
10181007

1019-
unsigned gapEnd = box ? box->start() : length;
1008+
unsigned gapEnd = run ? run->start() : length;
10201009
bool indicesIntersect = start <= gapEnd && end >= gapStart;
10211010
int gapLen = gapEnd - gapStart;
10221011
if (indicesIntersect && gapLen > 0) {
@@ -1029,13 +1018,9 @@ void CompositeEditCommand::deleteInsignificantText(Text& textNode, unsigned star
10291018
removed += gapLen;
10301019
}
10311020

1032-
prevBox = box;
1033-
if (box) {
1034-
if (++sortedTextBoxesPosition < sortedTextBoxes.size())
1035-
box = sortedTextBoxes[sortedTextBoxesPosition];
1036-
else
1037-
box = nullptr;
1038-
}
1021+
previousRun = run;
1022+
if (run)
1023+
run.traverseNextTextRunInTextOrder();
10391024
}
10401025

10411026
if (!str.isNull()) {

0 commit comments

Comments
 (0)