Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(903)

Unified Diff: Source/core/editing/PlainTextRange.cpp

Issue 560333002: Avoid more temporary ranges in connection with various TextIterators. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix mac build. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Range.cpp ('k') | Source/core/editing/SurroundingText.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/PlainTextRange.cpp
diff --git a/Source/core/editing/PlainTextRange.cpp b/Source/core/editing/PlainTextRange.cpp
index 736e500df8fd9b0c5f671580b309f27b49798fcd..e28859750025922665a62763629931c4da5d33ee 100644
--- a/Source/core/editing/PlainTextRange.cpp
+++ b/Source/core/editing/PlainTextRange.cpp
@@ -76,7 +76,8 @@ PassRefPtrWillBeRawPtr<Range> PlainTextRange::createRangeFor(const ContainerNode
size_t docTextPosition = 0;
bool startRangeFound = false;
- RefPtrWillBeRawPtr<Range> textRunRange = nullptr;
+ Position textRunStartPosition;
+ Position textRunEndPosition;
TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacementCharacter;
if (getRangeFor == ForSelection)
@@ -92,7 +93,9 @@ PassRefPtrWillBeRawPtr<Range> PlainTextRange::createRangeFor(const ContainerNode
for (; !it.atEnd(); it.advance()) {
int len = it.length();
- textRunRange = it.range();
+
+ textRunStartPosition = it.startPosition();
+ textRunEndPosition = it.endPosition();
bool foundStart = start() >= docTextPosition && start() <= docTextPosition + len;
bool foundEnd = end() >= docTextPosition && end() <= docTextPosition + len;
@@ -106,39 +109,37 @@ PassRefPtrWillBeRawPtr<Range> PlainTextRange::createRangeFor(const ContainerNode
if (len == 1 && (it.characterAt(0) == '\n' || it.isInsideReplacedElement())) {
it.advance();
if (!it.atEnd()) {
- RefPtrWillBeRawPtr<Range> range = it.range();
- textRunRange->setEnd(range->startContainer(), range->startOffset(), ASSERT_NO_EXCEPTION);
+ textRunEndPosition = it.startPosition();
} else {
- Position runStart = textRunRange->startPosition();
- Position runEnd = VisiblePosition(runStart).next().deepEquivalent();
+ Position runEnd = VisiblePosition(textRunStartPosition).next().deepEquivalent();
if (runEnd.isNotNull())
- textRunRange->setEnd(runEnd.containerNode(), runEnd.computeOffsetInContainerNode(), ASSERT_NO_EXCEPTION);
+ textRunEndPosition = createLegacyEditingPosition(runEnd.containerNode(), runEnd.computeOffsetInContainerNode());
}
}
}
if (foundStart) {
startRangeFound = true;
- if (textRunRange->startContainer()->isTextNode()) {
+ if (textRunStartPosition.containerNode()->isTextNode()) {
int offset = start() - docTextPosition;
- resultRange->setStart(textRunRange->startContainer(), offset + textRunRange->startOffset(), IGNORE_EXCEPTION);
+ resultRange->setStart(textRunStartPosition.containerNode(), offset + textRunStartPosition.offsetInContainerNode(), IGNORE_EXCEPTION);
} else {
if (start() == docTextPosition)
- resultRange->setStart(textRunRange->startContainer(), textRunRange->startOffset(), IGNORE_EXCEPTION);
+ resultRange->setStart(textRunStartPosition.containerNode(), textRunStartPosition.offsetInContainerNode(), IGNORE_EXCEPTION);
else
- resultRange->setStart(textRunRange->endContainer(), textRunRange->endOffset(), IGNORE_EXCEPTION);
+ resultRange->setStart(textRunEndPosition.containerNode(), textRunEndPosition.offsetInContainerNode(), IGNORE_EXCEPTION);
}
}
if (foundEnd) {
- if (textRunRange->startContainer()->isTextNode()) {
+ if (textRunStartPosition.containerNode()->isTextNode()) {
int offset = end() - docTextPosition;
- resultRange->setEnd(textRunRange->startContainer(), offset + textRunRange->startOffset(), IGNORE_EXCEPTION);
+ resultRange->setEnd(textRunStartPosition.containerNode(), offset + textRunStartPosition.offsetInContainerNode(), IGNORE_EXCEPTION);
} else {
if (end() == docTextPosition)
- resultRange->setEnd(textRunRange->startContainer(), textRunRange->startOffset(), IGNORE_EXCEPTION);
+ resultRange->setEnd(textRunStartPosition.containerNode(), textRunStartPosition.offsetInContainerNode(), IGNORE_EXCEPTION);
else
- resultRange->setEnd(textRunRange->endContainer(), textRunRange->endOffset(), IGNORE_EXCEPTION);
+ resultRange->setEnd(textRunEndPosition.containerNode(), textRunEndPosition.offsetInContainerNode(), IGNORE_EXCEPTION);
}
docTextPosition += len;
break;
@@ -150,7 +151,7 @@ PassRefPtrWillBeRawPtr<Range> PlainTextRange::createRangeFor(const ContainerNode
return nullptr;
if (length() && end() > docTextPosition) { // end() is out of bounds
- resultRange->setEnd(textRunRange->endContainer(), textRunRange->endOffset(), IGNORE_EXCEPTION);
+ resultRange->setEnd(textRunEndPosition.containerNode(), textRunEndPosition.offsetInContainerNode(), IGNORE_EXCEPTION);
}
return resultRange.release();
« no previous file with comments | « Source/core/dom/Range.cpp ('k') | Source/core/editing/SurroundingText.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698