Use simple/fast macro version of MinMax in JS

Use the simple macro version of {Min, Max} where possible to
improve performance

Follow-up to CR: https://codereview.chromium.org/1331993004

BUG=

Review URL: https://codereview.chromium.org/1390023003

Cr-Commit-Position: refs/heads/master@{#31162}
This commit is contained in:
karl 2015-10-07 11:32:47 -07:00 committed by Commit bot
parent 68126b52fa
commit 27c96c2621
6 changed files with 21 additions and 47 deletions

View File

@ -15,7 +15,6 @@ var Delete;
var GlobalArray = global.Array;
var InternalArray = utils.InternalArray;
var InternalPackedArray = utils.InternalPackedArray;
var MathMin;
var ObjectHasOwnProperty;
var ObjectIsFrozen;
var ObjectIsSealed;
@ -24,7 +23,6 @@ var unscopablesSymbol = utils.ImportNow("unscopables_symbol");
utils.Import(function(from) {
Delete = from.Delete;
MathMin = from.MathMin;
ObjectHasOwnProperty = from.ObjectHasOwnProperty;
ObjectIsFrozen = from.ObjectIsFrozen;
ObjectIsSealed = from.ObjectIsSealed;
@ -260,7 +258,7 @@ function SparseMove(array, start_i, del_count, len, num_additional_args) {
// Move data to new array.
var new_array = new InternalArray(
// Clamp array length to 2^32-1 to avoid early RangeError.
MathMin(len - del_count + num_additional_args, 0xffffffff));
MIN_SIMPLE(len - del_count + num_additional_args, 0xffffffff));
var big_indices;
var indices = %GetArrayKeys(array, len);
if (IS_NUMBER(indices)) {

View File

@ -13,15 +13,8 @@
var GlobalArrayBuffer = global.ArrayBuffer;
var GlobalObject = global.Object;
var MathMax;
var MathMin;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
});
// -------------------------------------------------------------------
function ArrayBufferConstructor(length) { // length = 1
@ -55,16 +48,16 @@ function ArrayBufferSlice(start, end) {
var first;
var byte_length = %_ArrayBufferGetByteLength(this);
if (relativeStart < 0) {
first = MathMax(byte_length + relativeStart, 0);
first = MAX_SIMPLE(byte_length + relativeStart, 0);
} else {
first = MathMin(relativeStart, byte_length);
first = MIN_SIMPLE(relativeStart, byte_length);
}
var relativeEnd = IS_UNDEFINED(end) ? byte_length : end;
var fin;
if (relativeEnd < 0) {
fin = MathMax(byte_length + relativeEnd, 0);
fin = MAX_SIMPLE(byte_length + relativeEnd, 0);
} else {
fin = MathMin(relativeEnd, byte_length);
fin = MIN_SIMPLE(relativeEnd, byte_length);
}
if (fin < first) {

View File

@ -15,16 +15,12 @@ var GetIterator;
var GetMethod;
var GlobalArray = global.Array;
var iteratorSymbol = utils.ImportNow("iterator_symbol");
var MathMax;
var MathMin;
var ObjectIsFrozen;
var ObjectDefineProperty;
utils.Import(function(from) {
GetIterator = from.GetIterator;
GetMethod = from.GetMethod;
MathMax = from.MathMax;
MathMin = from.MathMin;
ObjectIsFrozen = from.ObjectIsFrozen;
ObjectDefineProperty = from.ObjectDefineProperty;
});
@ -35,28 +31,28 @@ function InnerArrayCopyWithin(target, start, end, array, length) {
target = TO_INTEGER(target);
var to;
if (target < 0) {
to = MathMax(length + target, 0);
to = MAX_SIMPLE(length + target, 0);
} else {
to = MathMin(target, length);
to = MIN_SIMPLE(target, length);
}
start = TO_INTEGER(start);
var from;
if (start < 0) {
from = MathMax(length + start, 0);
from = MAX_SIMPLE(length + start, 0);
} else {
from = MathMin(start, length);
from = MIN_SIMPLE(start, length);
}
end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
var final;
if (end < 0) {
final = MathMax(length + end, 0);
final = MAX_SIMPLE(length + end, 0);
} else {
final = MathMin(end, length);
final = MIN_SIMPLE(end, length);
}
var count = MathMin(final - from, length - to);
var count = MIN_SIMPLE(final - from, length - to);
var direction = 1;
if (from < to && to < (from + count)) {
direction = -1;

View File

@ -12,13 +12,8 @@
// Imports
var GlobalObject = global.Object;
var MathMax;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
MathMax = from.MathMax;
});
// -------------------------------------------------------------------
@ -146,7 +141,7 @@ function AtomicsFutexWaitJS(ia, index, value, timeout) {
if (NUMBER_IS_NAN(timeout)) {
timeout = INFINITY;
} else {
timeout = MathMax(0, timeout);
timeout = MAX_SIMPLE(0, timeout);
}
}
return %AtomicsFutexWait(ia, index, value, timeout);
@ -158,14 +153,14 @@ function AtomicsFutexWakeJS(ia, index, count) {
if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
return UNDEFINED;
}
count = MathMax(0, TO_INTEGER(count));
count = MAX_SIMPLE(0, TO_INTEGER(count));
return %AtomicsFutexWake(ia, index, count);
}
function AtomicsFutexWakeOrRequeueJS(ia, index1, count, value, index2) {
CheckSharedInteger32TypedArray(ia);
index1 = TO_INTEGER(index1);
count = MathMax(0, TO_INTEGER(count));
count = MAX_SIMPLE(0, TO_INTEGER(count));
value = TO_INT32(value);
index2 = TO_INTEGER(index2);
if (index1 < 0 || index1 >= %_TypedArrayGetLength(ia) ||

View File

@ -48,8 +48,6 @@ var InnerArraySome;
var InnerArraySort;
var InnerArrayToLocaleString;
var IsNaN;
var MathMax;
var MathMin;
var PackedArrayReverse;
utils.Import(function(from) {
@ -72,8 +70,6 @@ utils.Import(function(from) {
InnerArraySort = from.InnerArraySort;
InnerArrayToLocaleString = from.InnerArrayToLocaleString;
IsNaN = from.IsNaN;
MathMax = from.MathMax;
MathMin = from.MathMin;
PackedArrayReverse = from.PackedArrayReverse;
});
@ -319,9 +315,9 @@ function TypedArraySlice(start, end) {
var k;
if (relativeStart < 0) {
k = MathMax(len + relativeStart, 0);
k = MAX_SIMPLE(len + relativeStart, 0);
} else {
k = MathMin(relativeStart, len);
k = MIN_SIMPLE(relativeStart, len);
}
var relativeEnd;
@ -333,12 +329,12 @@ function TypedArraySlice(start, end) {
var final;
if (relativeEnd < 0) {
final = MathMax(len + relativeEnd, 0);
final = MAX_SIMPLE(len + relativeEnd, 0);
} else {
final = MathMin(relativeEnd, len);
final = MIN_SIMPLE(relativeEnd, len);
}
var count = MathMax(final - k, 0);
var count = MAX_SIMPLE(final - k, 0);
var array = ConstructTypedArrayLike(this, count);
// The code below is the 'then' branch; the 'else' branch species
// a memcpy. Because V8 doesn't canonicalize NaN, the difference is

View File

@ -13,14 +13,10 @@
var GlobalJSON = global.JSON;
var InternalArray = utils.InternalArray;
var MathMax;
var MathMin;
var ObjectHasOwnProperty;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
ObjectHasOwnProperty = from.ObjectHasOwnProperty;
});
@ -215,7 +211,7 @@ function JSONStringify(value, replacer, space) {
}
var gap;
if (IS_NUMBER(space)) {
space = MathMax(0, MathMin(TO_INTEGER(space), 10));
space = MAX_SIMPLE(0, MIN_SIMPLE(TO_INTEGER(space), 10));
gap = %_SubString(" ", 0, space);
} else if (IS_STRING(space)) {
if (space.length > 10) {