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
This commit is contained in:
oleg@chromium.org 2010-02-25 16:46:37 +00:00
parent 05ae9effa3
commit a6940ef0a8

View File

@ -4152,10 +4152,14 @@ static Object* Runtime_NumberToInteger(Arguments args) {
NoHandleAllocation ha;
ASSERT(args.length() == 1);
Object* obj = args[0];
if (obj->IsSmi()) return obj;
CONVERT_DOUBLE_CHECKED(number, obj);
return Heap::NumberFromDouble(DoubleToInteger(number));
CONVERT_DOUBLE_CHECKED(number, args[0]);
// 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));
}
}
@ -4163,9 +4167,7 @@ static Object* Runtime_NumberToJSUint32(Arguments args) {
NoHandleAllocation ha;
ASSERT(args.length() == 1);
Object* obj = args[0];
if (obj->IsSmi() && Smi::cast(obj)->value() >= 0) return obj;
CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, obj);
CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, args[0]);
return Heap::NumberFromUint32(number);
}
@ -4174,10 +4176,14 @@ static Object* Runtime_NumberToJSInt32(Arguments args) {
NoHandleAllocation ha;
ASSERT(args.length() == 1);
Object* obj = args[0];
if (obj->IsSmi()) return obj;
CONVERT_DOUBLE_CHECKED(number, obj);
return Heap::NumberFromInt32(DoubleToInt32(number));
CONVERT_DOUBLE_CHECKED(number, args[0]);
// 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));
}
}