Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: src/harmony-typedarray.js

Issue 1345333002: src: Use simple/fast macro version of MinMax in JS (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Back from beginInt to startInt Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/arraybuffer.js ('K') | « src/harmony-atomics.js ('k') | src/json.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-typedarray.js
diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js
index 9d66e211e9800f97a3e6b3f4508d1e461333e4c7..7abd420f510b3c67a8daa584fb06e4b28999a94d 100644
--- a/src/harmony-typedarray.js
+++ b/src/harmony-typedarray.js
@@ -48,8 +48,6 @@ var InnerArraySome;
var InnerArraySort;
var InnerArrayToLocaleString;
var IsNaN;
-var MathMax;
-var MathMin;
var PackedArrayReverse;
var ToNumber;
@@ -73,8 +71,6 @@ utils.Import(function(from) {
InnerArraySort = from.InnerArraySort;
InnerArrayToLocaleString = from.InnerArrayToLocaleString;
IsNaN = from.IsNaN;
- MathMax = from.MathMax;
- MathMin = from.MathMin;
PackedArrayReverse = from.PackedArrayReverse;
ToNumber = from.ToNumber;
});
@@ -317,41 +313,39 @@ function TypedArraySlice(start, end) {
if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
var len = %_TypedArrayGetLength(this);
- var relativeStart = TO_INTEGER(start);
-
- var k;
- if (relativeStart < 0) {
- k = MathMax(len + relativeStart, 0);
+ var startInt = TO_INTEGER(start);
+ if (!IS_UNDEFINED(end)) {
+ var endInt = TO_INTEGER(end);
+ var srcLength = %_TypedArrayGetLength(this);
} else {
- k = MathMin(relativeStart, len);
+ var srcLength = %_TypedArrayGetLength(this);
+ var endInt = srcLength;
}
- var relativeEnd;
- if (IS_UNDEFINED(end)) {
- relativeEnd = len;
+ if (startInt < 0) {
+ startInt = MAX_SIMPLE(len + startInt, 0);
} else {
- relativeEnd = TO_INTEGER(end);
+ startInt = MIN_SIMPLE(startInt, len);
}
- var final;
- if (relativeEnd < 0) {
- final = MathMax(len + relativeEnd, 0);
+ if (endInt < 0) {
+ endInt = MAX_SIMPLE(len + endInt, 0);
} else {
- final = MathMin(relativeEnd, len);
+ endInt = MIN_SIMPLE(endInt, len);
}
- var count = MathMax(final - k, 0);
+ var count = MAX_SIMPLE(endInt - startInt, 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
// unobservable.
var n = 0;
- while (k < final) {
- var kValue = this[k];
+ while (startInt < endInt) {
+ var kValue = this[startInt];
// TODO(littledan): The spec says to throw on an error in setting;
// does this throw?
array[n] = kValue;
- k++;
+ startInt++;
n++;
}
return array;
« src/arraybuffer.js ('K') | « src/harmony-atomics.js ('k') | src/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698