Bug 1587069: slightly simplify `RangeBoundaryBase` constructors. r=smaug
authorMirko Brodesser <mbrodesser@mozilla.com>
Wed, 09 Oct 2019 10:07:46 +0000
changeset 496937 bd5d7f97fb3625ea16af3c7234de1f3436991081
parent 496936 8176f1d3873b384c26333c73074d7c22df586f34
child 496938 71e0aaf161bf0b61cd3d3eee9ea988956f4629fd
push id36671
push usershindli@mozilla.com
push dateWed, 09 Oct 2019 16:04:03 +0000
treeherdermozilla-central@0efb4f268d16 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1587069
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1587069: slightly simplify `RangeBoundaryBase` constructors. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D48651
dom/base/RangeBoundary.h
--- a/dom/base/RangeBoundary.h
+++ b/dom/base/RangeBoundary.h
@@ -51,41 +51,40 @@ class RangeBoundaryBase {
   friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback&,
                                           RangeBoundary&, const char*,
                                           uint32_t);
   friend void ImplCycleCollectionUnlink(RangeBoundary&);
 
  public:
   RangeBoundaryBase(nsINode* aContainer, nsIContent* aRef)
       : mParent(aContainer), mRef(aRef) {
-    if (!mRef) {
-      mOffset = mozilla::Some(0);
-    } else {
+    if (mRef) {
       NS_WARNING_ASSERTION(mRef->GetParentNode() == mParent,
                            "Initializing RangeBoundary with invalid value");
-      mOffset.reset();
+    } else {
+      mOffset.emplace(0);
     }
   }
 
   RangeBoundaryBase(nsINode* aContainer, int32_t aOffset)
       : mParent(aContainer), mRef(nullptr), mOffset(mozilla::Some(aOffset)) {
     if (mParent && mParent->IsContainerNode()) {
       // Find a reference node
-      if (aOffset == static_cast<int32_t>(aContainer->GetChildCount())) {
-        mRef = aContainer->GetLastChild();
+      if (aOffset == static_cast<int32_t>(mParent->GetChildCount())) {
+        mRef = mParent->GetLastChild();
       } else if (aOffset != 0) {
         mRef = mParent->GetChildAt_Deprecated(aOffset - 1);
       }
 
       NS_WARNING_ASSERTION(mRef || aOffset == 0,
                            "Constructing RangeBoundary with invalid value");
+
+      NS_WARNING_ASSERTION(!mRef || mRef->GetParentNode() == mParent,
+                           "Constructing RangeBoundary with invalid value");
     }
-
-    NS_WARNING_ASSERTION(!mRef || mRef->GetParentNode() == mParent,
-                         "Constructing RangeBoundary with invalid value");
   }
 
   RangeBoundaryBase() : mParent(nullptr), mRef(nullptr) {}
 
   // Needed for initializing RawRangeBoundary from an existing RangeBoundary.
   template <typename PT, typename RT>
   explicit RangeBoundaryBase(const RangeBoundaryBase<PT, RT>& aOther)
       : mParent(aOther.mParent), mRef(aOther.mRef), mOffset(aOther.mOffset) {}