Bug 1105895 - Use JSInlineString where possible in ConcatStrings(). r=jandem.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 06 Jan 2015 15:41:35 -0800
changeset 222578 51e4e9fcde248895ce6713cdb52cb7e2713f9425
parent 222577 c2845100484dfbeb1063bc3c22f3fca715d366b6
child 222579 e95a4191ea5eddc3e1543fa26633bef16a008d38
push id28068
push usercbook@mozilla.com
push dateThu, 08 Jan 2015 13:16:34 +0000
treeherdermozilla-central@2880e05d5e32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1105895
milestone37.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 1105895 - Use JSInlineString where possible in ConcatStrings(). r=jandem.
js/src/vm/String.cpp
--- a/js/src/vm/String.cpp
+++ b/js/src/vm/String.cpp
@@ -480,42 +480,44 @@ js::ConcatStrings(ThreadSafeContext *cx,
     if (!JSString::validateLength(cx, wholeLength))
         return nullptr;
 
     bool isLatin1 = left->hasLatin1Chars() && right->hasLatin1Chars();
     bool canUseFatInline = isLatin1
                            ? JSFatInlineString::latin1LengthFits(wholeLength)
                            : JSFatInlineString::twoByteLengthFits(wholeLength);
     if (canUseFatInline && cx->isJSContext()) {
-        JSFatInlineString *str = NewGCFatInlineString<allowGC>(cx);
+        Latin1Char *latin1Buf;
+        char16_t *twoByteBuf;
+        JSInlineString *str = isLatin1
+            ? AllocateFatInlineString<allowGC>(cx, wholeLength, &latin1Buf)
+            : AllocateFatInlineString<allowGC>(cx, wholeLength, &twoByteBuf);
         if (!str)
             return nullptr;
 
         AutoCheckCannotGC nogc;
         ScopedThreadSafeStringInspector leftInspector(left);
         ScopedThreadSafeStringInspector rightInspector(right);
         if (!leftInspector.ensureChars(cx, nogc) || !rightInspector.ensureChars(cx, nogc))
             return nullptr;
 
         if (isLatin1) {
-            Latin1Char *buf = str->initLatin1(wholeLength);
-            PodCopy(buf, leftInspector.latin1Chars(), leftLen);
-            PodCopy(buf + leftLen, rightInspector.latin1Chars(), rightLen);
-            buf[wholeLength] = 0;
+            PodCopy(latin1Buf, leftInspector.latin1Chars(), leftLen);
+            PodCopy(latin1Buf + leftLen, rightInspector.latin1Chars(), rightLen);
+            latin1Buf[wholeLength] = 0;
         } else {
-            char16_t *buf = str->initTwoByte(wholeLength);
             if (leftInspector.hasTwoByteChars())
-                PodCopy(buf, leftInspector.twoByteChars(), leftLen);
+                PodCopy(twoByteBuf, leftInspector.twoByteChars(), leftLen);
             else
-                CopyAndInflateChars(buf, leftInspector.latin1Chars(), leftLen);
+                CopyAndInflateChars(twoByteBuf, leftInspector.latin1Chars(), leftLen);
             if (rightInspector.hasTwoByteChars())
-                PodCopy(buf + leftLen, rightInspector.twoByteChars(), rightLen);
+                PodCopy(twoByteBuf + leftLen, rightInspector.twoByteChars(), rightLen);
             else
-                CopyAndInflateChars(buf + leftLen, rightInspector.latin1Chars(), rightLen);
-            buf[wholeLength] = 0;
+                CopyAndInflateChars(twoByteBuf + leftLen, rightInspector.latin1Chars(), rightLen);
+            twoByteBuf[wholeLength] = 0;
         }
 
         return str;
     }
 
     return JSRope::new_<allowGC>(cx, left, right, wholeLength);
 }