Bug 1587433: part 8) Remove superfluous `RangeBoundaryBase::Offset()` overload. r=smaug
☠☠ backed out by c0c22dbdd5b8 ☠ ☠
authorMirko Brodesser <mbrodesser@mozilla.com>
Wed, 11 Dec 2019 12:26:19 +0000
changeset 507078 18f8d61039b0705cb0c40d5640e54c174da3ce84
parent 507077 69ad70a4f85e79b26e1a86b6f134f4854a326eb1
child 507079 c0c22dbdd5b8d9cd13d58e7a1894655404911801
push id36922
push userncsoregi@mozilla.com
push dateMon, 16 Dec 2019 17:21:47 +0000
treeherdermozilla-central@27d0d6cc2131 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1587433
milestone73.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 1587433: part 8) Remove superfluous `RangeBoundaryBase::Offset()` overload. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D54504
dom/base/RangeBoundary.h
--- a/dom/base/RangeBoundary.h
+++ b/dom/base/RangeBoundary.h
@@ -6,16 +6,18 @@
 
 #ifndef mozilla_RangeBoundary_h
 #define mozilla_RangeBoundary_h
 
 #include "nsCOMPtr.h"
 #include "nsIContent.h"
 #include "mozilla/Maybe.h"
 
+class nsRange;
+
 namespace mozilla {
 
 template <typename T, typename U>
 class EditorDOMPointBase;
 
 // This class will maintain a reference to the child immediately
 // before the boundary's offset. We try to avoid computing the
 // offset as much as possible and just ensure mRef points to the
@@ -43,16 +45,18 @@ typedef RangeBoundaryBase<nsINode*, nsIC
 // AddRef/Release calls.
 template <typename ParentType, typename RefType>
 class RangeBoundaryBase {
   template <typename T, typename U>
   friend class RangeBoundaryBase;
   template <typename T, typename U>
   friend class EditorDOMPointBase;
 
+  friend nsRange;
+
   friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback&,
                                           RangeBoundary&, const char*,
                                           uint32_t);
   friend void ImplCycleCollectionUnlink(RangeBoundary&);
 
   static const uint32_t kFallbackOffset = 0;
 
  public:
@@ -149,70 +153,76 @@ class RangeBoundaryBase {
    *         kValidOffsets: if the offset is valid, it, Nothing{} otherwise.
    *         kValidOrInvalidOffsets: the internally stored offset, even if
    *                                 invalid, or if not available, a defined
    *                                 default value. That is, always some value.
    */
   Maybe<uint32_t> Offset(const OffsetFilter aOffsetFilter) const {
     switch (aOffsetFilter) {
       case OffsetFilter::kValidOffsets: {
-        return IsSetAndValid() ? Some(Offset()) : Nothing();
+        if (IsSetAndValid()) {
+          if (!mOffset) {
+            DetermineOffsetFromReference();
+          }
+        }
+        return mOffset;
       }
       case OffsetFilter::kValidOrInvalidOffsets: {
-        return Some(Offset());
+        if (mOffset.isSome()) {
+          return mOffset;
+        }
+
+        if (mParent) {
+          DetermineOffsetFromReference();
+          return mOffset;
+        }
+
+        return Some(kFallbackOffset);
       }
     }
   }
 
-  // TODO(mbrodesser): merge into the other Offset() method once all callers are
-  // switched to it.
-  uint32_t Offset() const {
-    if (mOffset.isSome()) {
-      return mOffset.value();
-    }
-
-    if (!mParent) {
-      return kFallbackOffset;
-    }
-
+ private:
+  void DetermineOffsetFromReference() const {
+    MOZ_ASSERT(mParent);
     MOZ_ASSERT(mRef);
     MOZ_ASSERT(mRef->GetParentNode() == mParent);
 
     const int32_t index = mParent->ComputeIndexOf(mRef);
     MOZ_ASSERT(index >= 0);
     mOffset.emplace(static_cast<uint32_t>(index + 1));
-
-    return mOffset.value();
   }
 
   void InvalidateOffset() {
     MOZ_ASSERT(mParent);
     MOZ_ASSERT(mParent->IsContainerNode(),
                "Range is positioned on a text node!");
 
     if (!mRef) {
       MOZ_ASSERT(mOffset.isSome() && mOffset.value() == 0,
                  "Invalidating offset of invalid RangeBoundary?");
       return;
     }
     mOffset.reset();
   }
 
+ public:
   bool IsSet() const { return mParent && (mRef || mOffset.isSome()); }
 
   bool IsSetAndValid() const {
     if (!IsSet()) {
       return false;
     }
 
     if (Ref()) {
       return Ref()->GetParentNode() == Container();
     }
-    return *Offset(OffsetFilter::kValidOrInvalidOffsets) <=
-           Container()->Length();
+
+    MOZ_ASSERT(mOffset.isSome());
+    return *mOffset <= Container()->Length();
   }
 
   bool IsStartOfContainer() const {
     // We're at the first point in the container if we don't have a reference,
     // and our offset is 0. If we don't have a Ref, we should already have an
     // offset, so we can just directly fetch it.
     return !Ref() && mOffset.value() == 0;
   }