Bug 1398751 - Part 2: Add fast path to convert int32 value to a code point. r=evilpie
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 12 Sep 2017 21:22:29 +0200
changeset 380347 f0f98cfb1a45ae37fecba156e217aca5f31f1c70
parent 380346 fdbf2ccf813ece8338dc0ef37030b1056e61bf26
child 380348 11a7e286a5b79cb09f5a70f2b5b979ceb3ac2e70
push id94902
push userryanvm@gmail.com
push dateWed, 13 Sep 2017 01:29:21 +0000
treeherdermozilla-inbound@f0f98cfb1a45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1398751
milestone57.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 1398751 - Part 2: Add fast path to convert int32 value to a code point. r=evilpie
js/src/jsstr.cpp
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -3307,16 +3307,26 @@ js::str_fromCharCode_one_arg(JSContext* 
 
     return CodeUnitToString(cx, ucode, rval);
 }
 
 static MOZ_ALWAYS_INLINE bool
 ToCodePoint(JSContext* cx, HandleValue code, uint32_t* codePoint)
 {
     // String.fromCodePoint, Steps 5.a-b.
+
+    // Fast path for the common case - the input is already an int32.
+    if (code.isInt32()) {
+        int32_t nextCP = code.toInt32();
+        if (nextCP >= 0 && nextCP <= int32_t(unicode::NonBMPMax)) {
+            *codePoint = uint32_t(nextCP);
+            return true;
+        }
+    }
+
     double nextCP;
     if (!ToNumber(cx, code, &nextCP))
         return false;
 
     // String.fromCodePoint, Steps 5.c-d.
     if (JS::ToInteger(nextCP) != nextCP || nextCP < 0 || nextCP > unicode::NonBMPMax) {
         ToCStringBuf cbuf;
         if (const char* numStr = NumberToCString(cx, &cbuf, nextCP))