Bug 918808 part 2 - Remove cruft from InflateStringToBuffer. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Sat, 21 Sep 2013 11:36:33 +0200
changeset 162024 bcf130e126aa0d8cb71b7fafffa536a1f4bf4cb5
parent 162023 4495cc6591c432af82e06dc60fe767dc41b4f4e1
child 162025 67fa64cde217038d28342a5af024129f9cc2bc28
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs918808
milestone27.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 918808 part 2 - Remove cruft from InflateStringToBuffer. r=luke
js/src/gc/Statistics.cpp
js/src/jsapi.cpp
js/src/jsatom.cpp
js/src/jsstr.cpp
js/src/jsstr.h
js/src/vm/StringBuffer.h
--- a/js/src/gc/Statistics.cpp
+++ b/js/src/gc/Statistics.cpp
@@ -129,26 +129,20 @@ class gcstats::StatisticsSerializer
         size_t nchars = strlen(buf);
         jschar *out = js_pod_malloc<jschar>(nchars + 1);
         if (!out) {
             oom_ = true;
             js_free(buf);
             return NULL;
         }
 
-        size_t outlen = nchars;
-        bool ok = InflateStringToBuffer(NULL, buf, nchars, out, &outlen);
+        InflateStringToBuffer(buf, nchars, out);
         js_free(buf);
-        if (!ok) {
-            oom_ = true;
-            js_free(out);
-            return NULL;
-        }
+
         out[nchars] = 0;
-
         return out;
     }
 
     char *finishCString() {
         if (oom_)
             return NULL;
 
         buf_.append('\0');
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -5458,17 +5458,35 @@ JS_ConcatStrings(JSContext *cx, HandleSt
     return ConcatStrings<CanGC>(cx, left, right);
 }
 
 JS_PUBLIC_API(bool)
 JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst, size_t *dstlenp)
 {
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
-    return InflateStringToBuffer(cx, src, srclen, dst, dstlenp);
+
+    if (!dst) {
+        *dstlenp = srclen;
+        return true;
+    }
+
+    size_t dstlen = *dstlenp;
+
+    if (srclen > dstlen) {
+        InflateStringToBuffer(src, dstlen, dst);
+
+        AutoSuppressGC suppress(cx);
+        JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BUFFER_TOO_SMALL);
+        return false;
+    }
+
+    InflateStringToBuffer(src, srclen, dst);
+    *dstlenp = srclen;
+    return true;
 }
 
 JS_PUBLIC_API(char *)
 JS_EncodeString(JSContext *cx, JSString *str)
 {
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
 
--- a/js/src/jsatom.cpp
+++ b/js/src/jsatom.cpp
@@ -383,23 +383,18 @@ js::AtomizeMaybeGC(ExclusiveContext *cx,
         /*
          * Avoiding the malloc in InflateString on shorter strings saves us
          * over 20,000 malloc calls on mozilla browser startup. This compares to
          * only 131 calls where the string is longer than a 31 char (net) buffer.
          * The vast majority of atomized strings are already in the hashtable. So
          * js::AtomizeString rarely has to copy the temp string we make.
          */
         jschar inflated[ATOMIZE_BUF_MAX];
-        size_t inflatedLength = ATOMIZE_BUF_MAX - 1;
-        if (!InflateStringToBuffer(cx->maybeJSContext(),
-                                   bytes, length, inflated, &inflatedLength))
-        {
-            return NULL;
-        }
-        return AtomizeAndCopyChars<allowGC>(cx, inflated, inflatedLength, ib);
+        InflateStringToBuffer(bytes, length, inflated);
+        return AtomizeAndCopyChars<allowGC>(cx, inflated, length, ib);
     }
 
     jschar *tbcharsZ = InflateString(cx, bytes, &length);
     if (!tbcharsZ)
         return NULL;
     return AtomizeAndTakeOwnership<allowGC>(cx, tbcharsZ, length, ib);
 }
 
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -4159,39 +4159,16 @@ js::DeflateStringToBuffer(JSContext *may
         return false;
     }
     for (size_t i = 0; i < srclen; i++)
         dst[i] = (char) src[i];
     *dstlenp = srclen;
     return true;
 }
 
-bool
-js::InflateStringToBuffer(JSContext *maybecx, const char *src, size_t srclen,
-                          jschar *dst, size_t *dstlenp)
-{
-    if (dst) {
-        size_t dstlen = *dstlenp;
-        if (srclen > dstlen) {
-            for (size_t i = 0; i < dstlen; i++)
-                dst[i] = (unsigned char) src[i];
-            if (maybecx) {
-                AutoSuppressGC suppress(maybecx);
-                JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL,
-                                     JSMSG_BUFFER_TOO_SMALL);
-            }
-            return false;
-        }
-        for (size_t i = 0; i < srclen; i++)
-            dst[i] = (unsigned char) src[i];
-    }
-    *dstlenp = srclen;
-    return true;
-}
-
 #define ____ false
 
 /*
  * Identifier start chars:
  * -      36:    $
  * -  65..90: A..Z
  * -      95:    _
  * - 97..122: a..z
--- a/js/src/jsstr.h
+++ b/js/src/jsstr.h
@@ -244,25 +244,25 @@ namespace js {
  * return the jschar that was malloc'ed. length is updated to the length of the
  * new string (in jschars). A null char is appended, but it is not included in
  * the length.
  */
 extern jschar *
 InflateString(ThreadSafeContext *cx, const char *bytes, size_t *length);
 
 /*
- * Inflate bytes to JS chars in an existing buffer. 'chars' must be large
- * enough for 'length' jschars. The buffer is NOT null-terminated.
- *
- * charsLength must be be initialized with the destination buffer size and, on
- * return, will contain on return the number of copied chars.
+ * Inflate bytes to JS chars in an existing buffer. 'dst' must be large
+ * enough for 'srclen' jschars. The buffer is NOT null-terminated.
  */
-extern bool
-InflateStringToBuffer(JSContext *maybecx, const char *bytes, size_t length,
-                      jschar *chars, size_t *charsLength);
+inline void
+InflateStringToBuffer(const char *src, size_t srclen, jschar *dst)
+{
+    for (size_t i = 0; i < srclen; i++)
+        dst[i] = (unsigned char) src[i];
+}
 
 /*
  * Deflate JS chars to bytes into a buffer. 'bytes' must be large enough for
  * 'length chars. The buffer is NOT null-terminated. The destination length
  * must to be initialized with the buffer size and will contain on return the
  * number of copied bytes.
  */
 extern bool
--- a/js/src/vm/StringBuffer.h
+++ b/js/src/vm/StringBuffer.h
@@ -117,20 +117,17 @@ StringBuffer::append(JSString *str)
 }
 
 inline bool
 StringBuffer::appendInflated(const char *cstr, size_t cstrlen)
 {
     size_t lengthBefore = length();
     if (!cb.growByUninitialized(cstrlen))
         return false;
-    mozilla::DebugOnly<size_t> oldcstrlen = cstrlen;
-    mozilla::DebugOnly<bool> ok = InflateStringToBuffer(NULL, cstr, cstrlen,
-                                                        begin() + lengthBefore, &cstrlen);
-    JS_ASSERT(ok && oldcstrlen == cstrlen);
+    InflateStringToBuffer(cstr, cstrlen, begin() + lengthBefore);
     return true;
 }
 
 /* ES5 9.8 ToString, appending the result to the string buffer. */
 extern bool
 ValueToStringBufferSlow(JSContext *cx, const Value &v, StringBuffer &sb);
 
 inline bool