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

Side by Side Diff: src/array.js

Issue 6580038: [Isolates] Merge from bleeding_edge, revisions 5934-6100. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « src/arm/stub-cache-arm.cc ('k') | src/assembler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 var result = %_FastAsciiArrayJoin(elements, ""); 152 var result = %_FastAsciiArrayJoin(elements, "");
153 if (!IS_UNDEFINED(result)) return result; 153 if (!IS_UNDEFINED(result)) return result;
154 return %StringBuilderConcat(elements, elements_length, ''); 154 return %StringBuilderConcat(elements, elements_length, '');
155 } finally { 155 } finally {
156 // Make sure to pop the visited array no matter what happens. 156 // Make sure to pop the visited array no matter what happens.
157 if (is_array) visited_arrays.pop(); 157 if (is_array) visited_arrays.pop();
158 } 158 }
159 } 159 }
160 160
161 161
162 function ConvertToString(e) { 162 function ConvertToString(x) {
163 if (e == null) return ''; 163 if (IS_STRING(x)) return x;
164 else return ToString(e); 164 if (IS_NUMBER(x)) return %_NumberToString(x);
165 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
166 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x));
165 } 167 }
166 168
167 169
168 function ConvertToLocaleString(e) { 170 function ConvertToLocaleString(e) {
169 if (e == null) { 171 if (e == null) {
170 return ''; 172 return '';
171 } else { 173 } else {
172 // e_obj's toLocaleString might be overwritten, check if it is a function. 174 // e_obj's toLocaleString might be overwritten, check if it is a function.
173 // Call ToString if toLocaleString is not a function. 175 // Call ToString if toLocaleString is not a function.
174 // See issue 877615. 176 // See issue 877615.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 throw new $TypeError('Array.prototype.toString is not generic'); 360 throw new $TypeError('Array.prototype.toString is not generic');
359 } 361 }
360 return Join(this, this.length, ',', ConvertToLocaleString); 362 return Join(this, this.length, ',', ConvertToLocaleString);
361 } 363 }
362 364
363 365
364 function ArrayJoin(separator) { 366 function ArrayJoin(separator) {
365 if (IS_UNDEFINED(separator)) { 367 if (IS_UNDEFINED(separator)) {
366 separator = ','; 368 separator = ',';
367 } else if (!IS_STRING(separator)) { 369 } else if (!IS_STRING(separator)) {
368 separator = ToString(separator); 370 separator = NonStringToString(separator);
369 } 371 }
370 372
371 var result = %_FastAsciiArrayJoin(this, separator); 373 var result = %_FastAsciiArrayJoin(this, separator);
372 if (!IS_UNDEFINED(result)) return result; 374 if (!IS_UNDEFINED(result)) return result;
373 375
374 var length = TO_UINT32(this.length); 376 return Join(this, TO_UINT32(this.length), separator, ConvertToString);
375 return Join(this, length, separator, ConvertToString);
376 } 377 }
377 378
378 379
379 // Removes the last element from the array and returns it. See 380 // Removes the last element from the array and returns it. See
380 // ECMA-262, section 15.4.4.6. 381 // ECMA-262, section 15.4.4.6.
381 function ArrayPop() { 382 function ArrayPop() {
382 var n = TO_UINT32(this.length); 383 var n = TO_UINT32(this.length);
383 if (n == 0) { 384 if (n == 0) {
384 this.length = n; 385 this.length = n;
385 return; 386 return;
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } else { 670 } else {
670 break; 671 break;
671 } 672 }
672 } 673 }
673 a[j + 1] = element; 674 a[j + 1] = element;
674 } 675 }
675 } 676 }
676 677
677 function QuickSort(a, from, to) { 678 function QuickSort(a, from, to) {
678 // Insertion sort is faster for short arrays. 679 // Insertion sort is faster for short arrays.
679 if (to - from <= 22) { 680 if (to - from <= 10) {
680 InsertionSort(a, from, to); 681 InsertionSort(a, from, to);
681 return; 682 return;
682 } 683 }
683 var pivot_index = $floor($random() * (to - from)) + from; 684 // Find a pivot as the median of first, last and middle element.
684 var pivot = a[pivot_index]; 685 var v0 = a[from];
685 // Issue 95: Keep the pivot element out of the comparisons to avoid 686 var v1 = a[to - 1];
686 // infinite recursion if comparefn(pivot, pivot) != 0. 687 var middle_index = from + ((to - from) >> 1);
687 %_SwapElements(a, from, pivot_index); 688 var v2 = a[middle_index];
688 var low_end = from; // Upper bound of the elements lower than pivot. 689 var c01 = %_CallFunction(global_receiver, v0, v1, comparefn);
689 var high_start = to; // Lower bound of the elements greater than pivot. 690 if (c01 > 0) {
691 // v1 < v0, so swap them.
692 var tmp = v0;
693 v0 = v1;
694 v1 = tmp;
695 } // v0 <= v1.
696 var c02 = %_CallFunction(global_receiver, v0, v2, comparefn);
697 if (c02 >= 0) {
698 // v2 <= v0 <= v1.
699 var tmp = v0;
700 v0 = v2;
701 v2 = v1;
702 v1 = tmp;
703 } else {
704 // v0 <= v1 && v0 < v2
705 var c12 = %_CallFunction(global_receiver, v1, v2, comparefn);
706 if (c12 > 0) {
707 // v0 <= v2 < v1
708 var tmp = v1;
709 v1 = v2;
710 v2 = tmp;
711 }
712 }
713 // v0 <= v1 <= v2
714 a[from] = v0;
715 a[to - 1] = v2;
716 var pivot = v1;
717 var low_end = from + 1; // Upper bound of elements lower than pivot.
718 var high_start = to - 1; // Lower bound of elements greater than pivot.
719 a[middle_index] = a[low_end];
720 a[low_end] = pivot;
721
690 // From low_end to i are elements equal to pivot. 722 // From low_end to i are elements equal to pivot.
691 // From i to high_start are elements that haven't been compared yet. 723 // From i to high_start are elements that haven't been compared yet.
692 for (var i = from + 1; i < high_start; ) { 724 partition: for (var i = low_end + 1; i < high_start; i++) {
693 var element = a[i]; 725 var element = a[i];
694 var order = %_CallFunction(global_receiver, element, pivot, comparefn); 726 var order = %_CallFunction(global_receiver, element, pivot, comparefn);
695 if (order < 0) { 727 if (order < 0) {
696 %_SwapElements(a, i, low_end); 728 %_SwapElements(a, i, low_end);
697 i++;
698 low_end++; 729 low_end++;
699 } else if (order > 0) { 730 } else if (order > 0) {
700 high_start--; 731 do {
732 high_start--;
733 if (high_start == i) break partition;
734 var top_elem = a[high_start];
735 order = %_CallFunction(global_receiver, top_elem, pivot, comparefn);
736 } while (order > 0);
701 %_SwapElements(a, i, high_start); 737 %_SwapElements(a, i, high_start);
702 } else { // order == 0 738 if (order < 0) {
703 i++; 739 %_SwapElements(a, i, low_end);
740 low_end++;
741 }
704 } 742 }
705 } 743 }
706 QuickSort(a, from, low_end); 744 QuickSort(a, from, low_end);
707 QuickSort(a, high_start, to); 745 QuickSort(a, high_start, to);
708 } 746 }
709 747
710 // Copies elements in the range 0..length from obj's prototype chain 748 // Copy elements in the range 0..length from obj's prototype chain
711 // to obj itself, if obj has holes. Returns one more than the maximal index 749 // to obj itself, if obj has holes. Return one more than the maximal index
712 // of a prototype property. 750 // of a prototype property.
713 function CopyFromPrototype(obj, length) { 751 function CopyFromPrototype(obj, length) {
714 var max = 0; 752 var max = 0;
715 for (var proto = obj.__proto__; proto; proto = proto.__proto__) { 753 for (var proto = obj.__proto__; proto; proto = proto.__proto__) {
716 var indices = %GetArrayKeys(proto, length); 754 var indices = %GetArrayKeys(proto, length);
717 if (indices.length > 0) { 755 if (indices.length > 0) {
718 if (indices[0] == -1) { 756 if (indices[0] == -1) {
719 // It's an interval. 757 // It's an interval.
720 var proto_length = indices[1]; 758 var proto_length = indices[1];
721 for (var i = 0; i < proto_length; i++) { 759 for (var i = 0; i < proto_length; i++) {
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), 1209 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1),
1172 "reduce", getFunction("reduce", ArrayReduce, 1), 1210 "reduce", getFunction("reduce", ArrayReduce, 1),
1173 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) 1211 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1)
1174 )); 1212 ));
1175 1213
1176 %FinishArrayPrototypeSetup($Array.prototype); 1214 %FinishArrayPrototypeSetup($Array.prototype);
1177 } 1215 }
1178 1216
1179 1217
1180 SetupArray(); 1218 SetupArray();
OLDNEW
« no previous file with comments | « src/arm/stub-cache-arm.cc ('k') | src/assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698