From 864cb782b0b1f78c026f2614db52347b12ddf457 Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Wed, 22 Jul 2020 00:54:31 +0000 Subject: [PATCH] Bug 1649121: part 56) Factor `DetermineFirstNode` out of `ContentIteratorBase::Initializer`. r=masayuki Hides details. Differential Revision: https://phabricator.services.mozilla.com/D84160 --- dom/base/ContentIterator.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/dom/base/ContentIterator.cpp b/dom/base/ContentIterator.cpp index f433f919ee47..708cfce052d1 100644 --- a/dom/base/ContentIterator.cpp +++ b/dom/base/ContentIterator.cpp @@ -196,6 +196,7 @@ class MOZ_STACK_CLASS ContentIteratorBase::Initializer final { nsresult Run(); private: + void DetermineFirstNode(); [[nodiscard]] nsresult DetermineLastNode(); bool IsCollapsedNonCharacterRange() const; @@ -249,8 +250,25 @@ nsresult ContentIteratorBase::Initializer::Run() { return NS_OK; } - // Find first node in range. + DetermineFirstNode(); + const nsresult rv = DetermineLastNode(); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + }; + // If either first or last is null, they both have to be null! + if (!mIterator.mFirst || !mIterator.mLast) { + mIterator.mFirst = nullptr; + mIterator.mLast = nullptr; + } + + mIterator.mCurNode = mIterator.mFirst; + mIterator.mIsDone = !mIterator.mCurNode; + + return NS_OK; +} + +void ContentIteratorBase::Initializer::DetermineFirstNode() { nsIContent* cChild = nullptr; // Try to get the child at our starting point. This might return null if @@ -319,21 +337,6 @@ nsresult ContentIteratorBase::Initializer::Run() { } } } - const nsresult rv = DetermineLastNode(); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - }; - - // If either first or last is null, they both have to be null! - if (!mIterator.mFirst || !mIterator.mLast) { - mIterator.mFirst = nullptr; - mIterator.mLast = nullptr; - } - - mIterator.mCurNode = mIterator.mFirst; - mIterator.mIsDone = !mIterator.mCurNode; - - return NS_OK; } nsresult ContentIteratorBase::Initializer::DetermineLastNode() {