Bug 1591191 - Move compare and EqualsIgnoreAsciiCase to nsTStringRepr. r=erahm
☠☠ backed out by 2457ce6fec56 ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 29 Oct 2019 20:09:00 +0000
changeset 500329 eb3d67637a9bbaaf8507c9748785c627bd33e723
parent 500328 07db0d2b41be5c68e142699b81685a951bfcb5d7
child 500330 8b916ab4900e23e4ffae0050d7f3496361b908b2
push id36762
push userdvarga@mozilla.com
push dateMon, 04 Nov 2019 16:12:30 +0000
treeherdermozilla-central@fa1628003bf9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1591191
milestone72.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 1591191 - Move compare and EqualsIgnoreAsciiCase to nsTStringRepr. r=erahm Zibi is working on replacing some string based APIs with some things that return substrings, so we could use this. Alternatively he'd have to do something like: Compare(myCSubstring, nsDependentCSubstring(aTag, strlen(aTag))) or something of that sort, which looks a bit uglier. Differential Revision: https://phabricator.services.mozilla.com/D50523
xpcom/string/nsStringObsolete.cpp
xpcom/string/nsTString.h
xpcom/string/nsTStringRepr.h
--- a/xpcom/string/nsStringObsolete.cpp
+++ b/xpcom/string/nsStringObsolete.cpp
@@ -847,24 +847,23 @@ void nsTString<T>::ReplaceChar(const cha
     if (i == kNotFound) break;
 
     data[i++] = aNewChar;
     data += i;
     lenRemaining -= i;
   }
 }
 
-/**
- * nsTString::Compare,CompareWithConversion,etc.
- */
+namespace mozilla {
+namespace detail {
 
 template <typename T>
 template <typename Q, typename EnableIfChar>
-int32_t nsTString<T>::Compare(const char_type* aString, bool aIgnoreCase,
-                              int32_t aCount) const {
+int32_t nsTStringRepr<T>::Compare(const char_type* aString, bool aIgnoreCase,
+                                  int32_t aCount) const {
   uint32_t strLen = char_traits::length(aString);
 
   int32_t maxCount = int32_t(XPCOM_MIN(this->mLength, strLen));
 
   int32_t compareCount;
   if (aCount < 0 || aCount > maxCount)
     compareCount = maxCount;
   else
@@ -881,18 +880,18 @@ int32_t nsTString<T>::Compare(const char
 
     if (this->mLength != strLen) result = (this->mLength < strLen) ? -1 : 1;
   }
   return result;
 }
 
 template <typename T>
 template <typename Q, typename EnableIfChar16>
-bool nsTString<T>::EqualsIgnoreCase(const incompatible_char_type* aString,
-                                    int32_t aCount) const {
+bool nsTStringRepr<T>::EqualsIgnoreCase(const incompatible_char_type* aString,
+                                        int32_t aCount) const {
   uint32_t strLen = nsCharTraits<char>::length(aString);
 
   int32_t maxCount = int32_t(XPCOM_MIN(this->mLength, strLen));
 
   int32_t compareCount;
   if (aCount < 0 || aCount > maxCount)
     compareCount = maxCount;
   else
@@ -908,16 +907,19 @@ bool nsTString<T>::EqualsIgnoreCase(cons
     // that the longer string is greater.
 
     if (this->mLength != strLen)
       result = 1;  // Arbitrarily using any number != 0
   }
   return result == 0;
 }
 
+}  // namespace detail
+}  // namespace mozilla
+
 /**
  * nsTString::ToDouble
  */
 
 template <>
 double nsTString<char>::ToDouble(TrailingCharsPolicy aTrailingCharsPolicy,
                                  nsresult* aErrorCode) const {
   double res = 0.0;
--- a/xpcom/string/nsTString.h
+++ b/xpcom/string/nsTString.h
@@ -277,45 +277,16 @@ class nsTString : public nsTSubstring<T>
    */
 
   int32_t RFindCharInSet(const char_type* aString, int32_t aOffset = -1) const;
   int32_t RFindCharInSet(const self_type& aString, int32_t aOffset = -1) const {
     return RFindCharInSet(aString.get(), aOffset);
   }
 
   /**
-   * Compares a given string to this string.
-   *
-   * @param   aString is the string to be compared
-   * @param   aIgnoreCase tells us how to treat case
-   * @param   aCount tells us how many chars to compare
-   * @return  -1,0,1
-   */
-  template <typename Q = T, typename EnableIfChar = mozilla::CharOnlyT<Q>>
-  int32_t Compare(const char_type* aString, bool aIgnoreCase = false,
-                  int32_t aCount = -1) const;
-
-  /**
-   * Equality check between given string and this string.
-   *
-   * @param   aString is the string to check
-   * @param   aIgnoreCase tells us how to treat case
-   * @param   aCount tells us how many chars to compare
-   * @return  boolean
-   */
-  template <typename Q = T, typename EnableIfChar = mozilla::CharOnlyT<Q>>
-  bool EqualsIgnoreCase(const char_type* aString, int32_t aCount = -1) const {
-    return Compare(aString, true, aCount) == 0;
-  }
-
-  template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
-  bool EqualsIgnoreCase(const incompatible_char_type* aString,
-                        int32_t aCount = -1) const;
-
-  /**
    * Perform string to double-precision float conversion.
    *
    * @param   aErrorCode will contain error if one occurs
    * @return  double-precision float rep of string value
    */
   double ToDouble(nsresult* aErrorCode) const;
 
   /**
--- a/xpcom/string/nsTStringRepr.h
+++ b/xpcom/string/nsTStringRepr.h
@@ -202,16 +202,45 @@ class nsTStringRepr {
   bool NS_FASTCALL Equals(const substring_tuple_type& aTuple) const;
   bool NS_FASTCALL Equals(const substring_tuple_type& aTuple,
                           const comparator_type& aComp) const;
 
   bool NS_FASTCALL Equals(const char_type* aData) const;
   bool NS_FASTCALL Equals(const char_type* aData,
                           const comparator_type& aComp) const;
 
+  /**
+   * Compares a given string to this string.
+   *
+   * @param   aString is the string to be compared
+   * @param   aIgnoreCase tells us how to treat case
+   * @param   aCount tells us how many chars to compare
+   * @return  -1,0,1
+   */
+  template <typename Q = T, typename EnableIfChar = mozilla::CharOnlyT<Q>>
+  int32_t Compare(const char_type* aString, bool aIgnoreCase = false,
+                  int32_t aCount = -1) const;
+
+  /**
+   * Equality check between given string and this string.
+   *
+   * @param   aString is the string to check
+   * @param   aIgnoreCase tells us how to treat case
+   * @param   aCount tells us how many chars to compare
+   * @return  boolean
+   */
+  template <typename Q = T, typename EnableIfChar = mozilla::CharOnlyT<Q>>
+  bool EqualsIgnoreCase(const char_type* aString, int32_t aCount = -1) const {
+    return Compare(aString, true, aCount) == 0;
+  }
+
+  template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
+  bool EqualsIgnoreCase(const incompatible_char_type* aString,
+                        int32_t aCount = -1) const;
+
 #if defined(MOZ_USE_CHAR16_WRAPPER)
   template <typename Q = T, typename EnableIfChar16 = Char16OnlyT<Q>>
   bool NS_FASTCALL Equals(char16ptr_t aData) const {
     return Equals(static_cast<const char16_t*>(aData));
   }
   template <typename Q = T, typename EnableIfChar16 = Char16OnlyT<Q>>
   bool NS_FASTCALL Equals(char16ptr_t aData,
                           const comparator_type& aComp) const {