Index: src/x87/code-stubs-x87.cc |
diff --git a/src/x87/code-stubs-x87.cc b/src/x87/code-stubs-x87.cc |
index 40fcd46337677022e9686976c61922f44529827c..1264dd9b2dad8ce513c55f318bee303bc2483580 100644 |
--- a/src/x87/code-stubs-x87.cc |
+++ b/src/x87/code-stubs-x87.cc |
@@ -2917,18 +2917,45 @@ void SubStringStub::Generate(MacroAssembler* masm) { |
void ToNumberStub::Generate(MacroAssembler* masm) { |
// The ToNumber stub takes one argument in eax. |
- Label check_heap_number, call_builtin; |
- __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
+ Label not_smi; |
+ __ JumpIfNotSmi(eax, ¬_smi, Label::kNear); |
__ Ret(); |
+ __ bind(¬_smi); |
- __ bind(&check_heap_number); |
+ Label not_heap_number; |
__ CompareMap(eax, masm->isolate()->factory()->heap_number_map()); |
- __ j(not_equal, &call_builtin, Label::kNear); |
+ __ j(not_equal, ¬_heap_number, Label::kNear); |
__ Ret(); |
+ __ bind(¬_heap_number); |
+ |
+ Label not_string, slow_string; |
+ __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi); |
+ // eax: object |
+ // edi: object map |
+ __ j(above_equal, ¬_string, Label::kNear); |
+ // Check if string has a cached array index. |
+ __ test(FieldOperand(eax, String::kHashFieldOffset), |
+ Immediate(String::kContainsCachedArrayIndexMask)); |
+ __ j(not_zero, &slow_string, Label::kNear); |
+ __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); |
+ __ IndexFromHash(eax, eax); |
+ __ Ret(); |
+ __ bind(&slow_string); |
+ __ pop(ecx); // Pop return address. |
+ __ push(eax); // Push argument. |
+ __ push(ecx); // Push return address. |
+ __ TailCallRuntime(Runtime::kStringToNumber, 1, 1); |
+ __ bind(¬_string); |
- __ bind(&call_builtin); |
- __ pop(ecx); // Pop return address. |
- __ push(eax); |
+ Label not_oddball; |
+ __ CmpInstanceType(edi, ODDBALL_TYPE); |
+ __ j(not_equal, ¬_oddball, Label::kNear); |
+ __ mov(eax, FieldOperand(eax, Oddball::kToNumberOffset)); |
+ __ Ret(); |
+ __ bind(¬_oddball); |
+ |
+ __ pop(ecx); // Pop return address. |
+ __ push(eax); // Push argument. |
__ push(ecx); // Push return address. |
__ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
} |