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

Side by Side Diff: src/array.js

Issue 1888: Avoid the creation of a string builder for joining one-element arrays. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 Google Inc. All Rights Reserved. 1 // Copyright 2006-2008 Google Inc. 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
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // visited arrays. 104 // visited arrays.
105 if (!%PushIfAbsent(visited_arrays, array)) return ''; 105 if (!%PushIfAbsent(visited_arrays, array)) return '';
106 } 106 }
107 107
108 // Attempt to convert the elements. 108 // Attempt to convert the elements.
109 try { 109 try {
110 if (UseSparseVariant(array, length, is_array) && separator === '') { 110 if (UseSparseVariant(array, length, is_array) && separator === '') {
111 return SparseJoin(array, length, convert); 111 return SparseJoin(array, length, convert);
112 } 112 }
113 113
114 // Fast case for one-element arrays.
115 if (length === 1) {
116 var e = array[0];
117 if (!IS_UNDEFINED(e) || (0 in array)) {
118 return convert(e);
119 }
120 }
121
114 var builder = new StringBuilder(); 122 var builder = new StringBuilder();
115 123
116 for (var i = 0; i < length; i++) { 124 for (var i = 0; i < length; i++) {
117 var e = array[i]; 125 var e = array[i];
118 if (i != 0) builder.add(separator); 126 if (i != 0) builder.add(separator);
119 if (!IS_UNDEFINED(e) || (i in array)) { 127 if (!IS_UNDEFINED(e) || (i in array)) {
120 builder.add(convert(e)); 128 builder.add(convert(e));
121 } 129 }
122 } 130 }
123 return builder.generate(); 131 return builder.generate();
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 ArrayEvery: 1, 919 ArrayEvery: 1,
912 ArrayMap: 1, 920 ArrayMap: 1,
913 ArrayIndexOf: 1, 921 ArrayIndexOf: 1,
914 ArrayLastIndexOf: 1, 922 ArrayLastIndexOf: 1,
915 ArrayPush: 1 923 ArrayPush: 1
916 }); 924 });
917 }; 925 };
918 926
919 927
920 SetupArray(); 928 SetupArray();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698