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

Unified Diff: sdk/lib/collection/hash_map.dart

Issue 18072004: Add fromIterable(s) constructors in SplayTreeMap and LinkedHashMap. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments. Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/collection/linked_hash_map.dart » ('j') | sdk/lib/collection/maps.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/hash_map.dart
diff --git a/sdk/lib/collection/hash_map.dart b/sdk/lib/collection/hash_map.dart
index 2d08e35890696589b494681de77adc10dd5cd36c..863276a25a57659c8aa210d14c55ebf9871a5eee 100644
--- a/sdk/lib/collection/hash_map.dart
+++ b/sdk/lib/collection/hash_map.dart
@@ -18,8 +18,6 @@ part of dart.collection;
class HashMap<K, V> implements Map<K, V> {
external HashMap();
- static _id(x) => x;
-
factory HashMap.from(Map<K, V> other) {
return new HashMap<K, V>()..addAll(other);
}
@@ -27,36 +25,13 @@ class HashMap<K, V> implements Map<K, V> {
factory HashMap.fromIterable(Iterable iterable,
floitsch 2013/06/27 16:04:32 Actually I think we need to copy the dart-doc from
zarah 2013/06/27 17:00:07 Done.
{K key(element), V value(element)}) {
HashMap<K, V> map = new HashMap<K, V>();
-
- if (key == null) key = _id;
- if (value == null) value = _id;
-
- for (var element in iterable) {
- map[key(element)] = value(element);
- }
-
+ Maps._fillMapWithMappedIterable(map, iterable, key: key, value: value);
return map;
}
factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) {
HashMap<K, V> map = new HashMap<K, V>();
-
- Iterator<K> keyIterator = keys.iterator;
- Iterator<V> valueIterator = values.iterator;
-
- bool hasNextKey = keyIterator.moveNext();
- bool hasNextValue = valueIterator.moveNext();
-
- while (hasNextKey && hasNextValue) {
- map[keyIterator.current] = valueIterator.current;
- hasNextKey = keyIterator.moveNext();
- hasNextValue = valueIterator.moveNext();
- }
-
- if (hasNextKey || hasNextValue) {
- throw new ArgumentError("Iterables do not have same length.");
- }
-
+ Maps._fillMapWithIterables(map, keys, values);
return map;
}
« no previous file with comments | « no previous file | sdk/lib/collection/linked_hash_map.dart » ('j') | sdk/lib/collection/maps.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698