From b3707c17d6f2abc2b49b3cb432a66385897a1f54 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Wed, 17 Apr 2013 16:37:11 +0000 Subject: [PATCH] Inline String.fromCharCode in hydrogen. BUG= Review URL: https://chromiumcodereview.appspot.com/14296009 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14315 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen.cc | 12 ++++++++++++ src/runtime.cc | 8 +++----- test/mjsunit/string-fromcharcode.js | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/hydrogen.cc b/src/hydrogen.cc index a628ec0..09e3fe9 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -8557,6 +8557,18 @@ bool HOptimizedGraphBuilder::TryInlineBuiltinMethodCall( return true; } break; + case kStringFromCharCode: + if (argument_count == 2 && check_type == RECEIVER_MAP_CHECK) { + AddCheckConstantFunction(expr->holder(), receiver, receiver_map); + HValue* argument = Pop(); + HValue* context = environment()->LookupContext(); + Drop(1); // Receiver. + HInstruction* result = + HStringCharFromCode::New(zone(), context, argument); + ast_context()->ReturnInstruction(result, expr->id()); + return true; + } + break; case kMathExp: if (!FLAG_fast_math) break; // Fall through if FLAG_fast_math. diff --git a/src/runtime.cc b/src/runtime.cc index 7e7d6d5..3fd5f6d 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -2417,11 +2417,9 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSGeneratorObject) { MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate, Object* char_code) { - uint32_t code; - if (char_code->ToArrayIndex(&code)) { - if (code <= 0xffff) { - return isolate->heap()->LookupSingleCharacterStringFromCode(code); - } + if (char_code->IsNumber()) { + return isolate->heap()->LookupSingleCharacterStringFromCode( + NumberToUint32(char_code) & 0xffff); } return isolate->heap()->empty_string(); } diff --git a/test/mjsunit/string-fromcharcode.js b/test/mjsunit/string-fromcharcode.js index 1986dda..631c043 100644 --- a/test/mjsunit/string-fromcharcode.js +++ b/test/mjsunit/string-fromcharcode.js @@ -25,8 +25,29 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Flags: --allow-natives-syntax + // Test String.fromCharCode. +// Test char codes larger than 0xffff. +var expected = ""; +for (var i = 100; i < 500; i++) { + expected += String.fromCharCode(i); +} + +function testCharCodeTruncation() { + var result = ""; + for (var i = 0x100000 + 100; i < 0x100000 + 500; i++) { + result += String.fromCharCode(i); + } + assertEquals(String.fromCharCode(0xFFFF), String.fromCharCode(0xFFFFFFFF)); + return result; +} + +assertEquals(expected, testCharCodeTruncation()); +assertEquals(expected, testCharCodeTruncation()); +%OptimizeFunctionOnNextCall(testCharCodeTruncation); +assertEquals(expected, testCharCodeTruncation()); // Test various receivers and arguments passed to String.fromCharCode. -- 2.7.4