Commit 6875d5e7 authored by lrn@chromium.org's avatar lrn@chromium.org

Optimize isFinite and isNaN.

Arithmetic on infinities and NaN is much slower than doing several exact comparisons.

Review URL: http://codereview.chromium.org/7830036

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9134 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 42e8bb62
...@@ -122,7 +122,7 @@ macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg)); ...@@ -122,7 +122,7 @@ macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
# Inline macros. Use %IS_VAR to make sure arg is evaluated only once. # Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || arg - arg == 0); macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg))); macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg))); macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0)); macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
const $isNaN = GlobalIsNaN; const $isNaN = GlobalIsNaN;
const $isFinite = GlobalIsFinite; const $isFinite = GlobalIsFinite;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -122,17 +121,15 @@ function SetUpLockedPrototype(constructor, fields, methods) { ...@@ -122,17 +121,15 @@ function SetUpLockedPrototype(constructor, fields, methods) {
// ECMA 262 - 15.1.4 // ECMA 262 - 15.1.4
function GlobalIsNaN(number) { function GlobalIsNaN(number) {
var n = ToNumber(number); if (!IS_NUMBER(number)) number = NonNumberToNumber(number);
return NUMBER_IS_NAN(n); return NUMBER_IS_NAN(number);
} }
// ECMA 262 - 15.1.5 // ECMA 262 - 15.1.5
function GlobalIsFinite(number) { function GlobalIsFinite(number) {
if (!IS_NUMBER(number)) number = NonNumberToNumber(number); if (!IS_NUMBER(number)) number = NonNumberToNumber(number);
return NUMBER_IS_FINITE(number);
// NaN - NaN == NaN, Infinity - Infinity == NaN, -Infinity - -Infinity == NaN.
return %_IsSmi(number) || number - number == 0;
} }
......
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