Bug 1344629 - Part 4: Cleanup: make string tuples not think in terms of "substring". r=dbaron
☠☠ backed out by 8d1f842be870 ☠ ☠
authorDavid Major <dmajor@mozilla.com>
Tue, 14 Mar 2017 10:02:55 +1300
changeset 347432 7d3c06b3eca939c10e6f37eae4efa686f874dc9c
parent 347431 e5df14c3db61b8e434dcadee3db0ae8c3be22ab0
child 347433 55eee7078ae4bc342710b9e3a7051a8aa177d872
push id31496
push usercbook@mozilla.com
push dateTue, 14 Mar 2017 13:21:57 +0000
treeherdermozilla-central@9a26ed658fdc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1344629
milestone55.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 1344629 - Part 4: Cleanup: make string tuples not think in terms of "substring". r=dbaron In the next patch, tuples will work on nsTStringRepr rather than nsTSubstring, so the notions of TO_SUBSTRING and substring_type are not quite right. MozReview-Commit-ID: LpUwmGQAWVO
xpcom/string/nsSubstringTuple.cpp
xpcom/string/nsTSubstringTuple.cpp
xpcom/string/nsTSubstringTuple.h
--- a/xpcom/string/nsSubstringTuple.cpp
+++ b/xpcom/string/nsSubstringTuple.cpp
@@ -1,19 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSubstringTuple.h"
 
-// convert fragment to |const substring_type&|
-#define TO_SUBSTRING(_v) (*(_v))
-
 // define nsSubstringTuple
 #include "string-template-def-unichar.h"
 #include "nsTSubstringTuple.cpp"
 #include "string-template-undef.h"
 
 // define nsCSubstringTuple
 #include "string-template-def-char.h"
 #include "nsTSubstringTuple.cpp"
--- a/xpcom/string/nsTSubstringTuple.cpp
+++ b/xpcom/string/nsTSubstringTuple.cpp
@@ -12,85 +12,60 @@
 
 nsTSubstringTuple_CharT::size_type
 nsTSubstringTuple_CharT::Length() const
 {
   mozilla::CheckedInt<size_type> len;
   if (mHead) {
     len = mHead->Length();
   } else {
-    len = TO_SUBSTRING(mFragA).Length();
+    len = mFragA->Length();
   }
 
-  len += TO_SUBSTRING(mFragB).Length();
+  len += mFragB->Length();
   MOZ_RELEASE_ASSERT(len.isValid(), "Substring tuple length is invalid");
   return len.value();
 }
 
 
 /**
  * writes the aggregate string to the given buffer. aBufLen is assumed
  * to be equal to or greater than the value returned by the Length()
  * method.  the string written to |aBuf| is not null-terminated.
  */
 
 void
 nsTSubstringTuple_CharT::WriteTo(char_type* aBuf, uint32_t aBufLen) const
 {
-  const substring_type& b = TO_SUBSTRING(mFragB);
-
-  MOZ_RELEASE_ASSERT(aBufLen >= b.Length(), "buffer too small");
-  uint32_t headLen = aBufLen - b.Length();
+  MOZ_RELEASE_ASSERT(aBufLen >= mFragB->Length(), "buffer too small");
+  uint32_t headLen = aBufLen - mFragB->Length();
   if (mHead) {
     mHead->WriteTo(aBuf, headLen);
   } else {
-    const substring_type& a = TO_SUBSTRING(mFragA);
-
-    MOZ_RELEASE_ASSERT(a.Length() == headLen, "buffer incorrectly sized");
-    char_traits::copy(aBuf, a.Data(), a.Length());
+    MOZ_RELEASE_ASSERT(mFragA->Length() == headLen, "buffer incorrectly sized");
+    char_traits::copy(aBuf, mFragA->Data(), mFragA->Length());
   }
 
-  char_traits::copy(aBuf + headLen, b.Data(), b.Length());
-
-#if 0
-  // we need to write out data into |aBuf|, ending at |aBuf + aBufLen|. So our
-  // data needs to precede |aBuf + aBufLen| exactly. We trust that the buffer
-  // was properly sized!
-
-  const substring_type& b = TO_SUBSTRING(mFragB);
-
-  NS_ASSERTION(aBufLen >= b.Length(), "buffer is too small");
-  char_traits::copy(aBuf + aBufLen - b.Length(), b.Data(), b.Length());
-
-  aBufLen -= b.Length();
-
-  if (mHead) {
-    mHead->WriteTo(aBuf, aBufLen);
-  } else {
-    const substring_type& a = TO_SUBSTRING(mFragA);
-    NS_ASSERTION(aBufLen == a.Length(), "buffer is too small");
-    char_traits::copy(aBuf, a.Data(), a.Length());
-  }
-#endif
+  char_traits::copy(aBuf + headLen, mFragB->Data(), mFragB->Length());
 }
 
 
 /**
  * returns true if this tuple is dependent on (i.e., overlapping with)
  * the given char sequence.
  */
 
 bool
 nsTSubstringTuple_CharT::IsDependentOn(const char_type* aStart,
                                        const char_type* aEnd) const
 {
   // we aStart with the right-most fragment since it is faster to check.
 
-  if (TO_SUBSTRING(mFragB).IsDependentOn(aStart, aEnd)) {
+  if (mFragB->IsDependentOn(aStart, aEnd)) {
     return true;
   }
 
   if (mHead) {
     return mHead->IsDependentOn(aStart, aEnd);
   }
 
-  return TO_SUBSTRING(mFragA).IsDependentOn(aStart, aEnd);
+  return mFragA->IsDependentOn(aStart, aEnd);
 }
--- a/xpcom/string/nsTSubstringTuple.h
+++ b/xpcom/string/nsTSubstringTuple.h
@@ -17,17 +17,16 @@
 class nsTSubstringTuple_CharT
 {
 public:
 
   typedef CharT                      char_type;
   typedef nsCharTraits<char_type>    char_traits;
 
   typedef nsTSubstringTuple_CharT    self_type;
-  typedef nsTSubstring_CharT         substring_type;
   typedef nsTSubstring_CharT         base_string_type;
   typedef uint32_t                   size_type;
 
 public:
 
   nsTSubstringTuple_CharT(const base_string_type* aStrA,
                           const base_string_type* aStrB)
     : mHead(nullptr)
@@ -59,19 +58,19 @@ public:
   /**
    * returns true if this tuple is dependent on (i.e., overlapping with)
    * the given char sequence.
    */
   bool IsDependentOn(const char_type* aStart, const char_type* aEnd) const;
 
 private:
 
-  const self_type*        mHead;
-  const base_string_type* mFragA;
-  const base_string_type* mFragB;
+  const self_type*        const mHead;
+  const base_string_type* const mFragA;
+  const base_string_type* const mFragB;
 };
 
 inline const nsTSubstringTuple_CharT
 operator+(const nsTSubstringTuple_CharT::base_string_type& aStrA,
           const nsTSubstringTuple_CharT::base_string_type& aStrB)
 {
   return nsTSubstringTuple_CharT(&aStrA, &aStrB);
 }