[es6] Optimize TypedArray.subarray()

````
var array = new Uint8Array(65000);
var startDate = Date.now();
var counter = 0;
while (counter++ < 50000000) {
  array.subarray(start, end);
}
var endDate = Date.now();
print(endDate - startDate);
````

4200 ms -> 3500 ms (16.67%)

BUG=

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

Cr-Commit-Position: refs/heads/master@{#30770}
This commit is contained in:
karl 2015-09-16 09:21:33 -07:00 committed by Commit bot
parent b444da41ad
commit 1e2aecf363
2 changed files with 13 additions and 11 deletions

View File

@ -157,6 +157,8 @@ macro TO_NAME(arg) = (%_ToName(arg));
macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null");
macro HAS_OWN_PROPERTY(arg, index) = (%_CallFunction(arg, index, ObjectHasOwnProperty));
macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array));
macro MAX_SIMPLE(argA, argB) = (argA < argB ? argB : argA);
macro MIN_SIMPLE(argA, argB) = (argA < argB ? argA : argB);
# Private names.
macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym));

View File

@ -37,13 +37,9 @@ endmacro
TYPED_ARRAYS(DECLARE_GLOBALS)
var MathMax;
var MathMin;
var ToNumber;
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
ToNumber = from.ToNumber;
});
@ -210,25 +206,29 @@ function NAMESubArray(begin, end) {
}
var beginInt = TO_INTEGER(begin);
if (!IS_UNDEFINED(end)) {
end = TO_INTEGER(end);
var endInt = TO_INTEGER(end);
var srcLength = %_TypedArrayGetLength(this);
} else {
var srcLength = %_TypedArrayGetLength(this);
var endInt = srcLength;
}
var srcLength = %_TypedArrayGetLength(this);
if (beginInt < 0) {
beginInt = MathMax(0, srcLength + beginInt);
beginInt = MAX_SIMPLE(0, srcLength + beginInt);
} else {
beginInt = MathMin(srcLength, beginInt);
beginInt = MIN_SIMPLE(beginInt, srcLength);
}
var endInt = IS_UNDEFINED(end) ? srcLength : end;
if (endInt < 0) {
endInt = MathMax(0, srcLength + endInt);
endInt = MAX_SIMPLE(0, srcLength + endInt);
} else {
endInt = MathMin(endInt, srcLength);
endInt = MIN_SIMPLE(endInt, srcLength);
}
if (endInt < beginInt) {
endInt = beginInt;
}
var newLength = endInt - beginInt;
var beginByteOffset =
%_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;