Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
| 8 // in runtime.js: | 8 // in runtime.js: |
| 9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
| 10 | 10 |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 } | 857 } |
| 858 a[j + 1] = element; | 858 a[j + 1] = element; |
| 859 } | 859 } |
| 860 }; | 860 }; |
| 861 | 861 |
| 862 var GetThirdIndex = function(a, from, to) { | 862 var GetThirdIndex = function(a, from, to) { |
| 863 var t_array = []; | 863 var t_array = []; |
| 864 // Use both 'from' and 'to' to determine the pivot candidates. | 864 // Use both 'from' and 'to' to determine the pivot candidates. |
| 865 var increment = 200 + ((to - from) & 15); | 865 var increment = 200 + ((to - from) & 15); |
| 866 for (var i = from + 1; i < to - 1; i += increment) { | 866 for (var i = from + 1; i < to - 1; i += increment) { |
| 867 t_array.push([i, a[i]]); | 867 ArrayPush.call(t_array, [i, a[i]]); |
|
arv (Not doing code reviews)
2014/09/10 15:47:39
%_CallFunction(t_array, [i, a[i]], ArrayPush)
But
| |
| 868 } | 868 } |
| 869 t_array.sort(function(a, b) { | 869 ArraySort.call(t_array, function(a, b) { |
|
arv (Not doing code reviews)
2014/09/10 15:47:39
%_CallFunction
| |
| 870 return %_CallFunction(receiver, a[1], b[1], comparefn) } ); | 870 return %_CallFunction(receiver, a[1], b[1], comparefn); |
| 871 }); | |
| 871 var third_index = t_array[t_array.length >> 1][0]; | 872 var third_index = t_array[t_array.length >> 1][0]; |
| 872 return third_index; | 873 return third_index; |
| 873 } | 874 } |
| 874 | 875 |
| 875 var QuickSort = function QuickSort(a, from, to) { | 876 var QuickSort = function QuickSort(a, from, to) { |
| 876 var third_index = 0; | 877 var third_index = 0; |
| 877 while (true) { | 878 while (true) { |
| 878 // Insertion sort is faster for short arrays. | 879 // Insertion sort is faster for short arrays. |
| 879 if (to - from <= 10) { | 880 if (to - from <= 10) { |
| 880 InsertionSort(a, from, to); | 881 InsertionSort(a, from, to); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 955 QuickSort(a, from, low_end); | 956 QuickSort(a, from, low_end); |
| 956 from = high_start; | 957 from = high_start; |
| 957 } | 958 } |
| 958 } | 959 } |
| 959 }; | 960 }; |
| 960 | 961 |
| 961 // Copy elements in the range 0..length from obj's prototype chain | 962 // Copy elements in the range 0..length from obj's prototype chain |
| 962 // to obj itself, if obj has holes. Return one more than the maximal index | 963 // to obj itself, if obj has holes. Return one more than the maximal index |
| 963 // of a prototype property. | 964 // of a prototype property. |
| 964 var CopyFromPrototype = function CopyFromPrototype(obj, length) { | 965 var CopyFromPrototype = function CopyFromPrototype(obj, length) { |
| 966 var hasOwnProperty = $Object.prototype.hasOwnProperty; | |
|
arv (Not doing code reviews)
2014/09/10 15:47:39
Either use %HasOwnProperty or ObjectHasOwnProperty
| |
| 965 var max = 0; | 967 var max = 0; |
| 966 for (var proto = %GetPrototype(obj); proto; proto = %GetPrototype(proto)) { | 968 for (var proto = %GetPrototype(obj); proto; proto = %GetPrototype(proto)) { |
| 967 var indices = %GetArrayKeys(proto, length); | 969 var indices = %GetArrayKeys(proto, length); |
| 968 if (IS_NUMBER(indices)) { | 970 if (IS_NUMBER(indices)) { |
| 969 // It's an interval. | 971 // It's an interval. |
| 970 var proto_length = indices; | 972 var proto_length = indices; |
| 971 for (var i = 0; i < proto_length; i++) { | 973 for (var i = 0; i < proto_length; i++) { |
| 972 if (!obj.hasOwnProperty(i) && proto.hasOwnProperty(i)) { | 974 if (!hasOwnProperty.call(obj, i) && hasOwnProperty.call(proto, i)) { |
|
arv (Not doing code reviews)
2014/09/10 15:47:39
call could have been replaced too :'(
Use
%_Call
| |
| 973 obj[i] = proto[i]; | 975 obj[i] = proto[i]; |
| 974 if (i >= max) { max = i + 1; } | 976 if (i >= max) { max = i + 1; } |
| 975 } | 977 } |
| 976 } | 978 } |
| 977 } else { | 979 } else { |
| 978 for (var i = 0; i < indices.length; i++) { | 980 for (var i = 0; i < indices.length; i++) { |
| 979 var index = indices[i]; | 981 var index = indices[i]; |
| 980 if (!IS_UNDEFINED(index) && | 982 if (!IS_UNDEFINED(index) && |
| 981 !obj.hasOwnProperty(index) && proto.hasOwnProperty(index)) { | 983 !hasOwnProperty.call(obj, index) && hasOwnProperty.call(proto, ind ex)) { |
| 982 obj[index] = proto[index]; | 984 obj[index] = proto[index]; |
| 983 if (index >= max) { max = index + 1; } | 985 if (index >= max) { max = index + 1; } |
| 984 } | 986 } |
| 985 } | 987 } |
| 986 } | 988 } |
| 987 } | 989 } |
| 988 return max; | 990 return max; |
| 989 }; | 991 }; |
| 990 | 992 |
| 991 // Set a value of "undefined" on all indices in the range from..to | 993 // Set a value of "undefined" on all indices in the range from..to |
| 992 // where a prototype of obj has an element. I.e., shadow all prototype | 994 // where a prototype of obj has an element. I.e., shadow all prototype |
| 993 // elements in that range. | 995 // elements in that range. |
| 994 var ShadowPrototypeElements = function(obj, from, to) { | 996 var ShadowPrototypeElements = function(obj, from, to) { |
| 997 var hasOwnProperty = $Object.prototype.hasOwnProperty; | |
| 995 for (var proto = %GetPrototype(obj); proto; proto = %GetPrototype(proto)) { | 998 for (var proto = %GetPrototype(obj); proto; proto = %GetPrototype(proto)) { |
| 996 var indices = %GetArrayKeys(proto, to); | 999 var indices = %GetArrayKeys(proto, to); |
| 997 if (IS_NUMBER(indices)) { | 1000 if (IS_NUMBER(indices)) { |
| 998 // It's an interval. | 1001 // It's an interval. |
| 999 var proto_length = indices; | 1002 var proto_length = indices; |
| 1000 for (var i = from; i < proto_length; i++) { | 1003 for (var i = from; i < proto_length; i++) { |
| 1001 if (proto.hasOwnProperty(i)) { | 1004 if (hasOwnProperty.call(proto, i)) { |
| 1002 obj[i] = UNDEFINED; | 1005 obj[i] = UNDEFINED; |
| 1003 } | 1006 } |
| 1004 } | 1007 } |
| 1005 } else { | 1008 } else { |
| 1006 for (var i = 0; i < indices.length; i++) { | 1009 for (var i = 0; i < indices.length; i++) { |
| 1007 var index = indices[i]; | 1010 var index = indices[i]; |
| 1008 if (!IS_UNDEFINED(index) && from <= index && | 1011 if (!IS_UNDEFINED(index) && from <= index && |
| 1009 proto.hasOwnProperty(index)) { | 1012 hasOwnProperty.call(proto, index)) { |
| 1010 obj[index] = UNDEFINED; | 1013 obj[index] = UNDEFINED; |
| 1011 } | 1014 } |
| 1012 } | 1015 } |
| 1013 } | 1016 } |
| 1014 } | 1017 } |
| 1015 }; | 1018 }; |
| 1016 | 1019 |
| 1017 var SafeRemoveArrayHoles = function SafeRemoveArrayHoles(obj) { | 1020 var SafeRemoveArrayHoles = function SafeRemoveArrayHoles(obj) { |
| 1018 // Copy defined elements from the end to fill in all holes and undefineds | 1021 // Copy defined elements from the end to fill in all holes and undefineds |
| 1019 // in the beginning of the array. Write undefineds and holes at the end | 1022 // in the beginning of the array. Write undefineds and holes at the end |
| 1020 // after loop is finished. | 1023 // after loop is finished. |
| 1021 var first_undefined = 0; | 1024 var first_undefined = 0; |
| 1022 var last_defined = length - 1; | 1025 var last_defined = length - 1; |
| 1023 var num_holes = 0; | 1026 var num_holes = 0; |
| 1024 while (first_undefined < last_defined) { | 1027 while (first_undefined < last_defined) { |
| 1025 // Find first undefined element. | 1028 // Find first undefined element. |
| 1026 while (first_undefined < last_defined && | 1029 while (first_undefined < last_defined && |
| 1027 !IS_UNDEFINED(obj[first_undefined])) { | 1030 !IS_UNDEFINED(obj[first_undefined])) { |
| 1028 first_undefined++; | 1031 first_undefined++; |
| 1029 } | 1032 } |
| 1030 // Maintain the invariant num_holes = the number of holes in the original | 1033 // Maintain the invariant num_holes = the number of holes in the original |
| 1031 // array with indices <= first_undefined or > last_defined. | 1034 // array with indices <= first_undefined or > last_defined. |
| 1032 if (!obj.hasOwnProperty(first_undefined)) { | 1035 if (!hasOwnProperty.call(obj, first_undefined)) { |
| 1033 num_holes++; | 1036 num_holes++; |
| 1034 } | 1037 } |
| 1035 | 1038 |
| 1036 // Find last defined element. | 1039 // Find last defined element. |
| 1037 while (first_undefined < last_defined && | 1040 while (first_undefined < last_defined && |
| 1038 IS_UNDEFINED(obj[last_defined])) { | 1041 IS_UNDEFINED(obj[last_defined])) { |
| 1039 if (!obj.hasOwnProperty(last_defined)) { | 1042 if (!$Object.prototype.hasOwnProperty.call(obj, last_defined)) { |
| 1040 num_holes++; | 1043 num_holes++; |
| 1041 } | 1044 } |
| 1042 last_defined--; | 1045 last_defined--; |
| 1043 } | 1046 } |
| 1044 if (first_undefined < last_defined) { | 1047 if (first_undefined < last_defined) { |
| 1045 // Fill in hole or undefined. | 1048 // Fill in hole or undefined. |
| 1046 obj[first_undefined] = obj[last_defined]; | 1049 obj[first_undefined] = obj[last_defined]; |
| 1047 obj[last_defined] = UNDEFINED; | 1050 obj[last_defined] = UNDEFINED; |
| 1048 } | 1051 } |
| 1049 } | 1052 } |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1546 )); | 1549 )); |
| 1547 | 1550 |
| 1548 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( | 1551 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( |
| 1549 "join", getFunction("join", ArrayJoin), | 1552 "join", getFunction("join", ArrayJoin), |
| 1550 "pop", getFunction("pop", ArrayPop), | 1553 "pop", getFunction("pop", ArrayPop), |
| 1551 "push", getFunction("push", ArrayPush) | 1554 "push", getFunction("push", ArrayPush) |
| 1552 )); | 1555 )); |
| 1553 } | 1556 } |
| 1554 | 1557 |
| 1555 SetUpArray(); | 1558 SetUpArray(); |
| OLD | NEW |