Bug 1263764 - Make the external string API's Truncate compatible with the internal API's Truncate. r=froydnj
authorJonathan Watt <jwatt@jwatt.org>
Fri, 01 Apr 2016 16:17:35 +0100
changeset 330691 b5600b3a7deb840b40307ac6cbfac96ea71f50ae
parent 330690 355e8bb48aeeef736df7ca21351f7e87caf90668
child 330692 7ec8bfb9bbd455dae46cfe363de70afa3d2ddf24
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1263764
milestone48.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 1263764 - Make the external string API's Truncate compatible with the internal API's Truncate. r=froydnj
xpcom/glue/nsStringAPI.h
--- a/xpcom/glue/nsStringAPI.h
+++ b/xpcom/glue/nsStringAPI.h
@@ -221,17 +221,21 @@ public:
     Replace(aPos, 0, aReadable);
   }
 
   NS_HIDDEN_(void) Cut(index_type aCutStart, size_type aCutLength)
   {
     Replace(aCutStart, aCutLength, nullptr, 0);
   }
 
-  NS_HIDDEN_(void) Truncate() { SetLength(0); }
+  NS_HIDDEN_(void) Truncate(size_type aNewLength = 0)
+  {
+    NS_ASSERTION(aNewLength <= Length(), "Truncate cannot make string longer");
+    SetLength(aNewLength);
+  }
 
   /**
    * Remove all occurences of characters in aSet from the string.
    */
   NS_HIDDEN_(void) StripChars(const char* aSet);
 
   /**
    * Strip whitespace characters from the string.
@@ -638,17 +642,21 @@ public:
     Replace(aPos, 0, aReadable);
   }
 
   NS_HIDDEN_(void) Cut(index_type aCutStart, size_type aCutLength)
   {
     Replace(aCutStart, aCutLength, nullptr, 0);
   }
 
-  NS_HIDDEN_(void) Truncate() { SetLength(0); }
+  NS_HIDDEN_(void) Truncate(size_type aNewLength = 0)
+  {
+    NS_ASSERTION(aNewLength <= Length(), "Truncate cannot make string longer");
+    SetLength(aNewLength);
+  }
 
   /**
    * Remove all occurences of characters in aSet from the string.
    */
   NS_HIDDEN_(void) StripChars(const char* aSet);
 
   /**
    * Strip whitespace characters from the string.