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:
parent
05ae9effa3
commit
a6940ef0a8
@ -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.
|
||||||
return Heap::NumberFromDouble(DoubleToInteger(number));
|
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;
|
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) {
|
|||||||
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.
|
||||||
return Heap::NumberFromInt32(DoubleToInt32(number));
|
if (number > 0 && number <= Smi::kMaxValue) {
|
||||||
|
return Smi::FromInt(static_cast<int>(number));
|
||||||
|
} else {
|
||||||
|
return Heap::NumberFromInt32(DoubleToInt32(number));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user