Bug 1105895 - Use JSInlineString where possible in ConcatStrings(). r=jandem.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 06 Jan 2015 15:41:35 -0800
changeset 223055 a5f042eed356bf543b579f1985657bc14472585a
parent 223031 086396560012f598b2400b11c10bfe39be083429
child 223056 75b65a499a576e54fd9175e5203d96887b08c1e7
push id28082
push usercbook@mozilla.com
push dateMon, 12 Jan 2015 10:44:52 +0000
treeherdermozilla-central@643589c3ef94 [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,44 +480,46 @@ js::ConcatStrings(ExclusiveContext *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;
         JSLinearString *leftLinear = left->ensureLinear(cx);
         if (!leftLinear)
             return nullptr;
         JSLinearString *rightLinear = right->ensureLinear(cx);
         if (!rightLinear)
             return nullptr;
 
         if (isLatin1) {
-            Latin1Char *buf = str->initLatin1(wholeLength);
-            PodCopy(buf, leftLinear->latin1Chars(nogc), leftLen);
-            PodCopy(buf + leftLen, rightLinear->latin1Chars(nogc), rightLen);
-            buf[wholeLength] = 0;
+            PodCopy(latin1Buf, leftLinear->latin1Chars(nogc), leftLen);
+            PodCopy(latin1Buf + leftLen, rightLinear->latin1Chars(nogc), rightLen);
+            latin1Buf[wholeLength] = 0;
         } else {
-            char16_t *buf = str->initTwoByte(wholeLength);
             if (leftLinear->hasTwoByteChars())
-                PodCopy(buf, leftLinear->twoByteChars(nogc), leftLen);
+                PodCopy(twoByteBuf, leftLinear->twoByteChars(nogc), leftLen);
             else
-                CopyAndInflateChars(buf, leftLinear->latin1Chars(nogc), leftLen);
+                CopyAndInflateChars(twoByteBuf, leftLinear->latin1Chars(nogc), leftLen);
             if (rightLinear->hasTwoByteChars())
-                PodCopy(buf + leftLen, rightLinear->twoByteChars(nogc), rightLen);
+                PodCopy(twoByteBuf + leftLen, rightLinear->twoByteChars(nogc), rightLen);
             else
-                CopyAndInflateChars(buf + leftLen, rightLinear->latin1Chars(nogc), rightLen);
-            buf[wholeLength] = 0;
+                CopyAndInflateChars(twoByteBuf + leftLen, rightLinear->latin1Chars(nogc), rightLen);
+            twoByteBuf[wholeLength] = 0;
         }
 
         return str;
     }
 
     return JSRope::new_<allowGC>(cx, left, right, wholeLength);
 }