Bug 1038099 - Make JS_NewMaybeExternalString return thin (but not fat) inline Latin-1 strings when the provided chars/length will fit within one. r=sfink
authorJeff Walden <jwalden@mit.edu>
Mon, 12 Feb 2018 14:13:28 -0800
changeset 405581 0852d89a06a1edc09e4ecc70977b0d71bd90b2a4
parent 405580 8e44cbf5be82d0b949544ad5a40eced6c690b385
child 405582 7190898a5b12b25dbf680c2b27e419f0f80321c2
push id100253
push userjwalden@mit.edu
push dateWed, 28 Feb 2018 00:02:25 +0000
treeherdermozilla-inbound@7190898a5b12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1038099
milestone60.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 1038099 - Make JS_NewMaybeExternalString return thin (but not fat) inline Latin-1 strings when the provided chars/length will fit within one. r=sfink
js/src/vm/String.cpp
--- a/js/src/vm/String.cpp
+++ b/js/src/vm/String.cpp
@@ -1503,16 +1503,21 @@ JSString*
 NewMaybeExternalString(JSContext* cx, const char16_t* s, size_t n, const JSStringFinalizer* fin,
                        bool* allocatedExternal)
 {
     if (JSString* str = TryEmptyOrStaticString(cx, s, n)) {
         *allocatedExternal = false;
         return str;
     }
 
+    if (JSThinInlineString::lengthFits<Latin1Char>(n) && CanStoreCharsAsLatin1(s, n)) {
+        *allocatedExternal = false;
+        return NewInlineStringDeflated<AllowGC::CanGC>(cx, mozilla::Range<const char16_t>(s, n));
+    }
+
     ExternalStringCache& cache = cx->zone()->externalStringCache();
     if (JSString* str = cache.lookup(s, n)) {
         *allocatedExternal = false;
         return str;
     }
 
     JSString* str = JSExternalString::new_(cx, s, n, fin);
     if (!str)