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

Side by Side Diff: src/js/harmony-array.js

Issue 1410473002: Reland: Use simple/fast inline function version of MinMax in JS (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: use existing export in runtime Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 'use strict'; 7 'use strict';
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var GetIterator; 14 var GetIterator;
15 var GetMethod; 15 var GetMethod;
16 var GlobalArray = global.Array; 16 var GlobalArray = global.Array;
17 var iteratorSymbol = utils.ImportNow("iterator_symbol"); 17 var iteratorSymbol = utils.ImportNow("iterator_symbol");
18 var MathMax;
19 var MathMin;
20 var ObjectIsFrozen; 18 var ObjectIsFrozen;
21 var ObjectDefineProperty; 19 var ObjectDefineProperty;
20 var MaxSimple;
Jakob Kummerow 2015/10/15 14:18:48 nit: please preserve alpha-sorting
skomski 2015/10/15 15:17:58 Done.
21 var MinSimple;
22 22
23 utils.Import(function(from) { 23 utils.Import(function(from) {
24 GetIterator = from.GetIterator; 24 GetIterator = from.GetIterator;
25 GetMethod = from.GetMethod; 25 GetMethod = from.GetMethod;
26 MathMax = from.MathMax;
27 MathMin = from.MathMin;
28 ObjectIsFrozen = from.ObjectIsFrozen; 26 ObjectIsFrozen = from.ObjectIsFrozen;
29 ObjectDefineProperty = from.ObjectDefineProperty; 27 ObjectDefineProperty = from.ObjectDefineProperty;
28 MaxSimple = from.MaxSimple;
29 MinSimple = from.MinSimple;
30 }); 30 });
31 31
32 // ------------------------------------------------------------------- 32 // -------------------------------------------------------------------
33 33
34 function InnerArrayCopyWithin(target, start, end, array, length) { 34 function InnerArrayCopyWithin(target, start, end, array, length) {
35 target = TO_INTEGER(target); 35 target = TO_INTEGER(target);
36 var to; 36 var to;
37 if (target < 0) { 37 if (target < 0) {
38 to = MathMax(length + target, 0); 38 to = MaxSimple(length + target, 0);
39 } else { 39 } else {
40 to = MathMin(target, length); 40 to = MinSimple(target, length);
41 } 41 }
42 42
43 start = TO_INTEGER(start); 43 start = TO_INTEGER(start);
44 var from; 44 var from;
45 if (start < 0) { 45 if (start < 0) {
46 from = MathMax(length + start, 0); 46 from = MaxSimple(length + start, 0);
47 } else { 47 } else {
48 from = MathMin(start, length); 48 from = MinSimple(start, length);
49 } 49 }
50 50
51 end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); 51 end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
52 var final; 52 var final;
53 if (end < 0) { 53 if (end < 0) {
54 final = MathMax(length + end, 0); 54 final = MaxSimple(length + end, 0);
55 } else { 55 } else {
56 final = MathMin(end, length); 56 final = MinSimple(end, length);
57 } 57 }
58 58
59 var count = MathMin(final - from, length - to); 59 var count = MinSimple(final - from, length - to);
60 var direction = 1; 60 var direction = 1;
61 if (from < to && to < (from + count)) { 61 if (from < to && to < (from + count)) {
62 direction = -1; 62 direction = -1;
63 from = from + count - 1; 63 from = from + count - 1;
64 to = to + count - 1; 64 to = to + count - 1;
65 } 65 }
66 66
67 while (count > 0) { 67 while (count > 0) {
68 if (from in array) { 68 if (from in array) {
69 array[to] = array[from]; 69 array[to] = array[from];
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 289
290 utils.Export(function(to) { 290 utils.Export(function(to) {
291 to.ArrayFrom = ArrayFrom; 291 to.ArrayFrom = ArrayFrom;
292 to.InnerArrayCopyWithin = InnerArrayCopyWithin; 292 to.InnerArrayCopyWithin = InnerArrayCopyWithin;
293 to.InnerArrayFill = InnerArrayFill; 293 to.InnerArrayFill = InnerArrayFill;
294 to.InnerArrayFind = InnerArrayFind; 294 to.InnerArrayFind = InnerArrayFind;
295 to.InnerArrayFindIndex = InnerArrayFindIndex; 295 to.InnerArrayFindIndex = InnerArrayFindIndex;
296 }); 296 });
297 297
298 }) 298 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698