Commit a6940ef0 authored by oleg@chromium.org's avatar oleg@chromium.org

Optimize three Number2Integer functions in runtime.cc: remove the check that...

Optimize three Number2Integer functions in runtime.cc: remove the check that was already done in JavaScript, add simpler code in case we are getting a SMI 
result.

Code review: http://codereview.chromium.org/660084


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3954 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 05ae9eff
...@@ -4152,10 +4152,14 @@ static Object* Runtime_NumberToInteger(Arguments args) { ...@@ -4152,10 +4152,14 @@ static Object* Runtime_NumberToInteger(Arguments args) {
NoHandleAllocation ha; NoHandleAllocation ha;
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
Object* obj = args[0]; CONVERT_DOUBLE_CHECKED(number, args[0]);
if (obj->IsSmi()) return obj;
CONVERT_DOUBLE_CHECKED(number, obj); // We do not include 0 so that we don't have to treat +0 / -0 cases.
if (number > 0 && number <= Smi::kMaxValue) {
return Smi::FromInt(static_cast<int>(number));
} else {
return Heap::NumberFromDouble(DoubleToInteger(number)); return Heap::NumberFromDouble(DoubleToInteger(number));
}
} }
...@@ -4163,9 +4167,7 @@ static Object* Runtime_NumberToJSUint32(Arguments args) { ...@@ -4163,9 +4167,7 @@ static Object* Runtime_NumberToJSUint32(Arguments args) {
NoHandleAllocation ha; NoHandleAllocation ha;
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
Object* obj = args[0]; CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, args[0]);
if (obj->IsSmi() && Smi::cast(obj)->value() >= 0) return obj;
CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, obj);
return Heap::NumberFromUint32(number); return Heap::NumberFromUint32(number);
} }
...@@ -4174,10 +4176,14 @@ static Object* Runtime_NumberToJSInt32(Arguments args) { ...@@ -4174,10 +4176,14 @@ static Object* Runtime_NumberToJSInt32(Arguments args) {
NoHandleAllocation ha; NoHandleAllocation ha;
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
Object* obj = args[0]; CONVERT_DOUBLE_CHECKED(number, args[0]);
if (obj->IsSmi()) return obj;
CONVERT_DOUBLE_CHECKED(number, obj); // We do not include 0 so that we don't have to treat +0 / -0 cases.
if (number > 0 && number <= Smi::kMaxValue) {
return Smi::FromInt(static_cast<int>(number));
} else {
return Heap::NumberFromInt32(DoubleToInt32(number)); return Heap::NumberFromInt32(DoubleToInt32(number));
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment