Chromium Code Reviews| Index: dart/lib/compiler/implementation/lib/mockimpl.dart |
| diff --git a/dart/lib/compiler/implementation/lib/mockimpl.dart b/dart/lib/compiler/implementation/lib/mockimpl.dart |
| index b6f18055e7e65737ee6033ffd3f0a97f538179ab..fd6d6e1c978213ff68b52e2e82d22f112418dcf2 100644 |
| --- a/dart/lib/compiler/implementation/lib/mockimpl.dart |
| +++ b/dart/lib/compiler/implementation/lib/mockimpl.dart |
| @@ -142,27 +142,35 @@ class StringBase { |
| static String join(List<String> strings, String separator) { |
| checkNull(strings); |
| checkNull(separator); |
| - var result = ""; |
| - var first = true; |
| - for (var string in strings) { |
| - checkNull(string); |
| - if (string is !String) throw new IllegalArgumentException(string); |
| - if (!first) result += separator; // TODO(ahe): Use string buffer. |
| - result += string; // TODO(ahe): Use string buffer. |
| - first = false; |
| - } |
| - return result; |
| + if (separator is !String) throw new IllegalArgumentException(separator); |
| + return stringJoinUnchecked(_toJsStringArray(strings), separator); |
| } |
| static String concatAll(List<String> strings) { |
| + return stringJoinUnchecked(_toJsStringArray(strings), ""); |
| + } |
| + |
| + static List _toJsStringArray(List<String> strings) { |
| checkNull(strings); |
| - var result = ""; |
| - for (var string in strings) { |
| - checkNull(string); |
| - if (string is !String) throw new IllegalArgumentException(string); |
| - result = '$result$string'; // TODO(ahe): Use string buffer. |
| + var array; |
| + final length = strings.length; |
| + if (isJsArray(strings)) { |
| + array = strings; |
| + for (int i = 0; i < length; i++) { |
| + final string = strings[i]; |
| + checkNull(string); |
|
Lasse Reichstein Nielsen
2012/06/18 09:25:32
Do we really want to throw a NPE instead of an IAE
ahe
2012/06/18 10:39:16
This is what the other implementation does. I cann
|
| + if (string is !String) throw new IllegalArgumentException(string); |
| + } |
| + } else { |
| + array = new List(length); |
| + for (int i = 0; i < length; i++) { |
| + final string = strings[i]; |
| + checkNull(string); |
| + if (string is !String) throw new IllegalArgumentException(string); |
| + array[i] = string; |
| + } |
| } |
| - return result; |
| + return array; |
| } |
| } |