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

Unified Diff: runtime/lib/string_base.dart

Issue 11414069: Make mappedBy lazy. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Remove CollectionUtils.mappedBy in Swarm. Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/string_base.dart
diff --git a/runtime/lib/string_base.dart b/runtime/lib/string_base.dart
index eef5b02a47d363fdcf73089036c762d77ce49f81..b167e8027e5395da6244fca887100741092cfa81 100644
--- a/runtime/lib/string_base.dart
+++ b/runtime/lib/string_base.dart
@@ -332,34 +332,36 @@ class _StringBase {
String toLowerCase() native "String_toLowerCase";
// Implementations of Strings methods follow below.
- static String join(List<String> strings, String separator) {
- final int length = strings.length;
- if (length == 0) {
- return "";
- }
-
- List stringsList = strings;
- if (separator.length != 0) {
- stringsList = new List(2 * length - 1);
- stringsList[0] = strings[0];
- int j = 1;
- for (int i = 1; i < length; i++) {
- stringsList[j++] = separator;
- stringsList[j++] = strings[i];
+ static String join(Iterable<String> strings, String separator) {
+ bool first = true;
+ List<String> stringsList = <String>[];
+ for (String string in strings) {
+ if (first) {
+ first = false;
+ } else {
+ stringsList.add(separator);
}
+
+ if (string is! String) throw new ArgumentError(string);
+ stringsList.add(string);
}
return concatAll(stringsList);
}
- static String concatAll(List<String> strings) {
+ static String concatAll(Iterable<String> strings) {
_ObjectArray stringsArray;
if (strings is _ObjectArray) {
stringsArray = strings;
+ for (int i = 0; i < strings.length; i++) {
+ if (strings[i] is! String) throw new ArgumentError(strings[i]);
+ }
} else {
int len = strings.length;
stringsArray = new _ObjectArray(len);
- for (int i = 0; i < len; i++) {
- stringsArray[i] = strings[i];
+ int i = 0;
+ for (String string in strings) {
+ if (string is! String) throw new ArgumentError(string);
+ stringsArray[i++] = string;
}
}
return _concatAll(stringsArray);

Powered by Google App Engine
This is Rietveld 408576698