<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[210131] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/210131">210131</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2016-12-23 01:11:32 -0800 (Fri, 23 Dec 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Eliminate the use of lastChild in TextIterator
https://bugs.webkit.org/show_bug.cgi?id=166456
Reviewed by Antti Koivisto.
Just use the node we just existed in TextIterator::exitNode and in emitting additional new line
to eliminate the use of Node::lastChild.
Also initialize member variables in the declaration instead of the constructor to modernize the code.
* editing/TextIterator.cpp:
(WebCore::TextIterator::TextIterator):
(WebCore::TextIterator::advance):
(WebCore::TextIterator::exitNode):
* editing/TextIterator.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreeditingTextIteratorcpp">trunk/Source/WebCore/editing/TextIterator.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingTextIteratorh">trunk/Source/WebCore/editing/TextIterator.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (210130 => 210131)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-12-23 04:41:52 UTC (rev 210130)
+++ trunk/Source/WebCore/ChangeLog        2016-12-23 09:11:32 UTC (rev 210131)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-12-23 Ryosuke Niwa <rniwa@webkit.org>
+
+ Eliminate the use of lastChild in TextIterator
+ https://bugs.webkit.org/show_bug.cgi?id=166456
+
+ Reviewed by Antti Koivisto.
+
+ Just use the node we just existed in TextIterator::exitNode and in emitting additional new line
+ to eliminate the use of Node::lastChild.
+
+ Also initialize member variables in the declaration instead of the constructor to modernize the code.
+
+ * editing/TextIterator.cpp:
+ (WebCore::TextIterator::TextIterator):
+ (WebCore::TextIterator::advance):
+ (WebCore::TextIterator::exitNode):
+ * editing/TextIterator.h:
+
</ins><span class="cx"> 2016-12-22 Andy Estes <aestes@apple.com>
</span><span class="cx">
</span><span class="cx"> Reduce QuickLook.h include overhead
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingTextIteratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/TextIterator.cpp (210130 => 210131)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/TextIterator.cpp        2016-12-23 04:41:52 UTC (rev 210130)
+++ trunk/Source/WebCore/editing/TextIterator.cpp        2016-12-23 09:11:32 UTC (rev 210131)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> #include "HTMLNames.h"
</span><span class="cx"> #include "HTMLParagraphElement.h"
</span><span class="cx"> #include "HTMLProgressElement.h"
</span><ins>+#include "HTMLSlotElement.h"
</ins><span class="cx"> #include "HTMLTextAreaElement.h"
</span><span class="cx"> #include "HTMLTextFormControlElement.h"
</span><span class="cx"> #include "InlineTextBox.h"
</span><span class="lines">@@ -340,23 +341,6 @@
</span><span class="cx">
</span><span class="cx"> TextIterator::TextIterator(const Range* range, TextIteratorBehavior behavior)
</span><span class="cx"> : m_behavior(behavior)
</span><del>- , m_handledNode(false)
- , m_handledChildren(false)
- , m_startContainer(nullptr)
- , m_startOffset(0)
- , m_endContainer(nullptr)
- , m_endOffset(0)
- , m_positionNode(nullptr)
- , m_needsAnotherNewline(false)
- , m_textBox(nullptr)
- , m_remainingTextBox(nullptr)
- , m_firstLetterText(nullptr)
- , m_lastTextNode(nullptr)
- , m_lastTextNodeEndedWithCollapsedSpace(false)
- , m_lastCharacter(0)
- , m_sortedTextBoxesPosition(0)
- , m_hasEmitted(false)
- , m_handledFirstLetter(false)
</del><span class="cx"> {
</span><span class="cx"> // FIXME: Only m_positionNode above needs to be initialized if range is null.
</span><span class="cx"> if (!range)
</span><span class="lines">@@ -407,7 +391,7 @@
</span><span class="cx"> m_text = StringView();
</span><span class="cx">
</span><span class="cx"> // handle remembered node that needed a newline after the text node's newline
</span><del>- if (m_needsAnotherNewline) {
</del><ins>+ if (m_nodeForAdditionalNewline) {
</ins><span class="cx"> // Emit the extra newline, and position it *inside* m_node, after m_node's
</span><span class="cx"> // contents, in case it's a block, in the same way that we position the first
</span><span class="cx"> // newline. The range for the emitted newline should start where the line
</span><span class="lines">@@ -414,9 +398,8 @@
</span><span class="cx"> // break begins.
</span><span class="cx"> // FIXME: It would be cleaner if we emitted two newlines during the last
</span><span class="cx"> // iteration, instead of using m_needsAnotherNewline.
</span><del>- Node& baseNode = m_node->lastChild() ? *m_node->lastChild() : *m_node;
- emitCharacter('\n', *baseNode.parentNode(), &baseNode, 1, 1);
- m_needsAnotherNewline = false;
</del><ins>+ emitCharacter('\n', *m_nodeForAdditionalNewline->parentNode(), m_nodeForAdditionalNewline, 1, 1);
+ m_nodeForAdditionalNewline = nullptr;
</ins><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -475,11 +458,12 @@
</span><span class="cx"> if ((pastEnd && parentNode == m_endContainer) || m_endContainer->isDescendantOf(*parentNode))
</span><span class="cx"> return;
</span><span class="cx"> bool haveRenderer = m_node->renderer();
</span><ins>+ Node* exitedNode = m_node;
</ins><span class="cx"> m_node = parentNode;
</span><span class="cx"> m_fullyClippedStack.pop();
</span><span class="cx"> parentNode = m_node->parentOrShadowHostNode();
</span><span class="cx"> if (haveRenderer)
</span><del>- exitNode();
</del><ins>+ exitNode(exitedNode);
</ins><span class="cx"> if (m_positionNode) {
</span><span class="cx"> m_handledNode = true;
</span><span class="cx"> m_handledChildren = true;
</span><span class="lines">@@ -1096,7 +1080,7 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void TextIterator::exitNode()
</del><ins>+void TextIterator::exitNode(Node* exitedNode)
</ins><span class="cx"> {
</span><span class="cx"> // prevent emitting a newline when exiting a collapsed block at beginning of the range
</span><span class="cx"> // FIXME: !m_hasEmitted does not necessarily mean there was a collapsed block... it could
</span><span class="lines">@@ -1108,7 +1092,7 @@
</span><span class="cx"> // Emit with a position *inside* m_node, after m_node's contents, in
</span><span class="cx"> // case it is a block, because the run should start where the
</span><span class="cx"> // emitted character is positioned visually.
</span><del>- Node* baseNode = m_node->lastChild() ? m_node->lastChild() : m_node;
</del><ins>+ Node* baseNode = exitedNode;
</ins><span class="cx"> // FIXME: This shouldn't require the m_lastTextNode to be true, but we can't change that without making
</span><span class="cx"> // the logic in _web_attributedStringFromRange match. We'll get that for free when we switch to use
</span><span class="cx"> // TextIterator in _web_attributedStringFromRange.
</span><span class="lines">@@ -1123,8 +1107,9 @@
</span><span class="cx"> // insert a newline with a position following this block's contents.
</span><span class="cx"> emitCharacter('\n', *baseNode->parentNode(), baseNode, 1, 1);
</span><span class="cx"> // remember whether to later add a newline for the current node
</span><del>- ASSERT(!m_needsAnotherNewline);
- m_needsAnotherNewline = addNewline;
</del><ins>+ ASSERT(!m_nodeForAdditionalNewline);
+ if (addNewline)
+ m_nodeForAdditionalNewline = baseNode;
</ins><span class="cx"> } else if (addNewline)
</span><span class="cx"> // insert a newline with a position following this block's contents.
</span><span class="cx"> emitCharacter('\n', *baseNode->parentNode(), baseNode, 1, 1);
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingTextIteratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/TextIterator.h (210130 => 210131)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/TextIterator.h        2016-12-23 04:41:52 UTC (rev 210130)
+++ trunk/Source/WebCore/editing/TextIterator.h        2016-12-23 09:11:32 UTC (rev 210131)
</span><span class="lines">@@ -114,7 +114,7 @@
</span><span class="cx"> WEBCORE_EXPORT static Ref<Range> subrange(Range* entireRange, int characterOffset, int characterCount);
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- void exitNode();
</del><ins>+ void exitNode(Node*);
</ins><span class="cx"> bool shouldRepresentNodeOffsetZero();
</span><span class="cx"> bool shouldEmitSpaceBeforeAndAfterNode(Node&);
</span><span class="cx"> void representNodeOffsetZero();
</span><span class="lines">@@ -126,44 +126,46 @@
</span><span class="cx"> void emitCharacter(UChar, Node& characterNode, Node* offsetBaseNode, int textStartOffset, int textEndOffset);
</span><span class="cx"> void emitText(Text& textNode, RenderText&, int textStartOffset, int textEndOffset);
</span><span class="cx">
</span><del>- const TextIteratorBehavior m_behavior;
</del><ins>+ Node* baseNodeForEmittingNewLine() const;
</ins><span class="cx">
</span><ins>+ const TextIteratorBehavior m_behavior { TextIteratorDefaultBehavior };
+
</ins><span class="cx"> // Current position, not necessarily of the text being returned, but position as we walk through the DOM tree.
</span><del>- Node* m_node;
- int m_offset;
- bool m_handledNode;
- bool m_handledChildren;
</del><ins>+ Node* m_node { nullptr };
+ int m_offset { 0 };
+ bool m_handledNode { false };
+ bool m_handledChildren { false };
</ins><span class="cx"> BitStack m_fullyClippedStack;
</span><span class="cx">
</span><span class="cx"> // The range.
</span><del>- Node* m_startContainer;
- int m_startOffset;
- Node* m_endContainer;
- int m_endOffset;
- Node* m_pastEndNode;
</del><ins>+ Node* m_startContainer { nullptr };
+ int m_startOffset { 0 };
+ Node* m_endContainer { nullptr };
+ int m_endOffset { 0 };
+ Node* m_pastEndNode { nullptr };
</ins><span class="cx">
</span><span class="cx"> // The current text and its position, in the form to be returned from the iterator.
</span><del>- Node* m_positionNode;
- mutable Node* m_positionOffsetBaseNode;
- mutable int m_positionStartOffset;
- mutable int m_positionEndOffset;
</del><ins>+ Node* m_positionNode { nullptr };
+ mutable Node* m_positionOffsetBaseNode { nullptr };
+ mutable int m_positionStartOffset { 0 };
+ mutable int m_positionEndOffset { 0 };
</ins><span class="cx"> TextIteratorCopyableText m_copyableText;
</span><span class="cx"> StringView m_text;
</span><span class="cx">
</span><span class="cx"> // Used when there is still some pending text from the current node; when these are false and null, we go back to normal iterating.
</span><del>- bool m_needsAnotherNewline;
- InlineTextBox* m_textBox;
</del><ins>+ Node* m_nodeForAdditionalNewline { nullptr };
+ InlineTextBox* m_textBox { nullptr };
</ins><span class="cx">
</span><span class="cx"> // Used when iterating over :first-letter text to save pointer to remaining text box.
</span><del>- InlineTextBox* m_remainingTextBox;
</del><ins>+ InlineTextBox* m_remainingTextBox { nullptr };
</ins><span class="cx">
</span><span class="cx"> // Used to point to RenderText object for :first-letter.
</span><del>- RenderText* m_firstLetterText;
</del><ins>+ RenderText* m_firstLetterText { nullptr };
</ins><span class="cx">
</span><span class="cx"> // Used to do the whitespace collapsing logic.
</span><del>- Text* m_lastTextNode;
- bool m_lastTextNodeEndedWithCollapsedSpace;
- UChar m_lastCharacter;
</del><ins>+ Text* m_lastTextNode { nullptr };
+ bool m_lastTextNodeEndedWithCollapsedSpace { false };
+ UChar m_lastCharacter { 0 };
</ins><span class="cx">
</span><span class="cx"> // Used to do simple line layout run logic.
</span><span class="cx"> bool m_nextRunNeedsWhitespace { false };
</span><span class="lines">@@ -173,13 +175,13 @@
</span><span class="cx">
</span><span class="cx"> // Used when text boxes are out of order (Hebrew/Arabic with embedded LTR text)
</span><span class="cx"> Vector<InlineTextBox*> m_sortedTextBoxes;
</span><del>- size_t m_sortedTextBoxesPosition;
</del><ins>+ size_t m_sortedTextBoxesPosition { 0 };
</ins><span class="cx">
</span><span class="cx"> // Used when deciding whether to emit a "positioning" (e.g. newline) before any other content
</span><del>- bool m_hasEmitted;
</del><ins>+ bool m_hasEmitted { false };
</ins><span class="cx">
</span><span class="cx"> // Used when deciding text fragment created by :first-letter should be looked into.
</span><del>- bool m_handledFirstLetter;
</del><ins>+ bool m_handledFirstLetter { false };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> // Iterates through the DOM range, returning all the text, and 0-length boundaries
</span></span></pre>
</div>
</div>
</body>
</html>