Backed out changeset 95377313608b (bug 1101337) for linux debug build bustage
authorWes Kocher <wkocher@mozilla.com>
Fri, 12 Dec 2014 16:34:43 -0800
changeset 245436 afd27046e00c0198fe30ae3da4d7f852ae93add3
parent 245435 599e1b8d3cbcbaaccf1f40ef4fb6244e2ad679b5
child 245437 0f5cdda7a611ca6666be252797b9ade4e7faca10
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1101337
milestone37.0a1
backs out95377313608be83f7ed1ef6b3b593e3b5478e839
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
Backed out changeset 95377313608b (bug 1101337) for linux debug build bustage
xpcom/string/nsSubstring.cpp
xpcom/string/nsTString.h
xpcom/string/nsTStringObsolete.cpp
xpcom/tests/TestStrings.cpp
--- a/xpcom/string/nsSubstring.cpp
+++ b/xpcom/string/nsSubstring.cpp
@@ -101,17 +101,17 @@ public:
 static nsStringStats gStringStats;
 #define STRING_STAT_INCREMENT(_s) (gStringStats.m ## _s ## Count)++
 #else
 #define STRING_STAT_INCREMENT(_s)
 #endif
 
 // ---------------------------------------------------------------------------
 
-void
+inline void
 ReleaseData(void* aData, uint32_t aFlags)
 {
   if (aFlags & nsSubstring::F_SHARED) {
     nsStringBuffer::FromData(aData)->Release();
   } else if (aFlags & nsSubstring::F_OWNED) {
     nsMemory::Free(aData);
     STRING_STAT_INCREMENT(AdoptFree);
 #ifdef NS_BUILD_REFCNT_LOGGING
--- a/xpcom/string/nsTString.h
+++ b/xpcom/string/nsTString.h
@@ -381,21 +381,16 @@ public:
    *  swaps occurence of 1 string for another
    */
 
   void ReplaceChar(char_type aOldChar, char_type aNewChar);
   void ReplaceChar(const char* aSet, char_type aNewChar);
 #ifdef CharT_is_PRUnichar
   void ReplaceChar(const char16_t* aSet, char16_t aNewChar);
 #endif
-  /**
-   * Replace all occurrences of aTarget with aNewValue.
-   * The complexity of this function is O(n+m), n being the length of the string
-   * and m being the length of aNewValue.
-   */
   void ReplaceSubstring(const self_type& aTarget, const self_type& aNewValue);
   void ReplaceSubstring(const char_type* aTarget, const char_type* aNewValue);
 
 
   /**
    *  This method trims characters found in aTrimSet from
    *  either end of the underlying string.
    *
@@ -458,24 +453,16 @@ protected:
   {
   }
 
   // allow subclasses to initialize fields directly
   nsTString_CharT(char_type* aData, size_type aLength, uint32_t aFlags)
     : substring_type(aData, aLength, aFlags)
   {
   }
-
-  struct Segment {
-    uint32_t mBegin, mLength;
-    Segment(uint32_t aBegin, uint32_t aLength)
-      : mBegin(aBegin)
-      , mLength(aLength)
-    {}
-  };
 };
 
 
 class nsTFixedString_CharT : public nsTString_CharT
 {
 public:
 
   typedef nsTFixedString_CharT self_type;
--- a/xpcom/string/nsTStringObsolete.cpp
+++ b/xpcom/string/nsTStringObsolete.cpp
@@ -1,15 +1,15 @@
 /* -*- 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 "nsTArray.h"
+
 
 /**
  * nsTString::Find
  *
  * aOffset specifies starting index
  * aCount specifies number of string compares (iterations)
  */
 
@@ -446,112 +446,41 @@ nsTString_CharT::ReplaceChar( const char
       break;
 
     data[i++] = aNewChar;
     data += i;
     lenRemaining -= i;
   }
 }
 
-void ReleaseData(void* aData, uint32_t aFlags);
-
 void
 nsTString_CharT::ReplaceSubstring( const char_type* aTarget, const char_type* aNewValue )
 {
   ReplaceSubstring(nsTDependentString_CharT(aTarget),
                    nsTDependentString_CharT(aNewValue));
 }
 
 void
 nsTString_CharT::ReplaceSubstring( const self_type& aTarget, const self_type& aNewValue )
 {
   if (aTarget.Length() == 0)
     return;
 
-  // Remember all of the non-matching parts.
-  nsAutoTArray<Segment, 16> nonMatching;
   uint32_t i = 0;
-  uint32_t newLength = 0;
-  while (true)
+  while (i < mLength)
   {
     int32_t r = FindSubstring(mData + i, mLength - i, static_cast<const char_type*>(aTarget.Data()), aTarget.Length(), false);
-    int32_t until = (r == kNotFound) ? mLength - i : r;
-    nonMatching.AppendElement(Segment(i, until));
-    newLength += until;
-    if (r == kNotFound) {
-      break;
-    }
-
-    newLength += aNewValue.Length();
-    i += r + aTarget.Length();
-    if (i >= mLength) {
-      // Add an auxiliary entry at the end of the list to help as an edge case
-      // for the algorithms below.
-      nonMatching.AppendElement(Segment(mLength, 0));
+    if (r == kNotFound)
       break;
-    }
-  }
-
-  // If there's only one non-matching segment, then the target string was not
-  // found, and there's nothing to do.
-  if (nonMatching.Length() == 1) {
-    MOZ_ASSERT(nonMatching[0].mBegin == 0 && nonMatching[0].mLength == mLength,
-               "We should have the correct non-matching segment.");
-    return;
-  }
-
-  // Make sure that we can mutate our buffer.
-  char_type* oldData;
-  uint32_t oldFlags;
-  if (!MutatePrep(XPCOM_MAX(mLength, newLength), &oldData, &oldFlags))
-    return;
-  if (oldData) {
-    // Copy all of the old data to the new buffer.
-    char_traits::copy(mData, oldData, XPCOM_MAX(mLength, newLength));
-    ::ReleaseData(oldData, oldFlags);
-  }
 
-  if (aTarget.Length() >= aNewValue.Length()) {
-    // In the shrinking case, start filling the buffer from the beginning.
-    const uint32_t delta = (aTarget.Length() - aNewValue.Length());
-    for (i = 1; i < nonMatching.Length(); ++i) {
-      // When we move the i'th non-matching segment into position, we need to
-      // account for the characters deleted by the previous |i| replacements by
-      // subtracting |i * delta|.
-      const char_type* sourceSegmentPtr = mData + nonMatching[i].mBegin;
-      char_type* destinationSegmentPtr = mData + nonMatching[i].mBegin - i * delta;
-      // Write the i'th replacement immediately before the new i'th non-matching
-      // segment.
-      char_traits::copy(destinationSegmentPtr - aNewValue.Length(),
-                        aNewValue.Data(), aNewValue.Length());
-      memmove(destinationSegmentPtr, sourceSegmentPtr,
-              sizeof(char_type) * nonMatching[i].mLength);
-    }
-  } else {
-    // In the growing case, start filling the buffer from the end.
-    const uint32_t delta = (aNewValue.Length() - aTarget.Length());
-    for (i = nonMatching.Length() - 1; i > 0; --i) {
-      // When we move the i'th non-matching segment into position, we need to
-      // account for the characters added by the previous |i| replacements by
-      // adding |i * delta|.
-      const char_type* sourceSegmentPtr = mData + nonMatching[i].mBegin;
-      char_type* destinationSegmentPtr = mData + nonMatching[i].mBegin + i * delta;
-      memmove(destinationSegmentPtr, sourceSegmentPtr,
-              sizeof(char_type) * nonMatching[i].mLength);
-      // Write the i'th replacement immediately before the new i'th non-matching
-      // segment.
-      char_traits::copy(destinationSegmentPtr - aNewValue.Length(),
-                        aNewValue.Data(), aNewValue.Length());
-    }
+    Replace(i + r, aTarget.Length(), aNewValue);
+    i += r + aNewValue.Length();
   }
+}
 
-  // Adjust the length and make sure the string is null terminated.
-  mLength = newLength;
-  mData[mLength] = char_type(0);
-}
 
 /**
  * nsTString::Trim
  */
 
 void
 nsTString_CharT::Trim( const char* aSet, bool aTrimLeading, bool aTrimTrailing, bool aIgnoreQuotes )
 {
--- a/xpcom/tests/TestStrings.cpp
+++ b/xpcom/tests/TestStrings.cpp
@@ -446,166 +446,16 @@ bool test_replace_substr_2()
 
     // we expect that newAcctName will be unchanged.
     if (!newAcctName.Equals(acctName))
       return false;
 
     return true;
   }
 
-bool test_replace_substr_3()
-  {
-    nsCString s;
-    s.Assign("abcabcabc");
-    s.ReplaceSubstring("ca", "X");
-    bool r = strcmp(s.get(), "abXbXbc") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcabcabc");
-    s.ReplaceSubstring("ca", "XYZ");
-    r = strcmp(s.get(), "abXYZbXYZbc") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcabcabc");
-    s.ReplaceSubstring("ca", "XY");
-    r = strcmp(s.get(), "abXYbXYbc") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcabcabc");
-    s.ReplaceSubstring("ca", "XYZ!");
-    r = strcmp(s.get(), "abXYZ!bXYZ!bc") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("bcd", "X");
-    r = strcmp(s.get(), "aXaXaX") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("bcd", "XYZ!");
-    r = strcmp(s.get(), "aXYZ!aXYZ!aXYZ!") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("bcd", "XY");
-    r = strcmp(s.get(), "aXYaXYaXY") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("bcd", "XYZABC");
-    r = strcmp(s.get(), "aXYZABCaXYZABCaXYZABC") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("bcd", "XYZ");
-    r = strcmp(s.get(), "aXYZaXYZaXYZ") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("bcd", "XYZ!");
-    r = strcmp(s.get(), "aXYZ!aXYZ!aXYZ!") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("ab", "X");
-    r = strcmp(s.get(), "XcdXcdXcd") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("ab", "XYZABC");
-    r = strcmp(s.get(), "XYZABCcdXYZABCcdXYZABCcd") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("ab", "XY");
-    r = strcmp(s.get(), "XYcdXYcdXYcd") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("ab", "XYZ!");
-    r = strcmp(s.get(), "XYZ!cdXYZ!cdXYZ!cd") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("notfound", "X");
-    r = strcmp(s.get(), "abcdabcdabcd") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    s.Assign("abcdabcdabcd");
-    s.ReplaceSubstring("notfound", "longlongstring");
-    r = strcmp(s.get(), "abcdabcdabcd") == 0;
-    if (!r)
-      {
-        printf("[s=%s]\n", s.get());
-        return false;
-      }
-
-    return true;
-  }
-
 bool test_strip_ws()
   {
     const char text[] = " a    $   ";
     nsCString s(text);
     s.StripWhitespace();
     bool r = strcmp(s.get(), "a$") == 0;
     if (!r)
       printf("[s=%s]\n", s.get());
@@ -1346,17 +1196,16 @@ tests[] =
     { "test_rfind_4", test_rfind_4 },
     { "test_findinreadable", test_findinreadable },
     { "test_rfindinreadable", test_rfindinreadable },
     { "test_distance", test_distance },
     { "test_length", test_length },
     { "test_trim", test_trim },
     { "test_replace_substr", test_replace_substr },
     { "test_replace_substr_2", test_replace_substr_2 },
-    { "test_replace_substr_3", test_replace_substr_3 },
     { "test_strip_ws", test_strip_ws },
     { "test_equals_ic", test_equals_ic },
     { "test_fixed_string", test_fixed_string },
     { "test_concat", test_concat },
     { "test_concat_2", test_concat_2 },
     { "test_concat_3", test_concat_3 },
     { "test_xpidl_string", test_xpidl_string },
     { "test_empty_assign", test_empty_assign },