diff --git a/lib/src/sortedmap.dart b/lib/src/sortedmap.dart index 5a5db24..36eac64 100644 --- a/lib/src/sortedmap.dart +++ b/lib/src/sortedmap.dart @@ -210,8 +210,12 @@ class _SortedMap extends MapBase return; } if (this is! FilteredMap) { - _sortedEntries - .addAll(other.entries.map((e) => ordering.mapEntry(e.key, e.value))); + var entries = other.entries; + if (entries is! Iterable<_MapEntryWithIndex>) { + entries = entries.map<_MapEntryWithIndex>( + (e) => ordering.mapEntry(e.key, e.value)); + } + _sortedEntries.addAll(entries); _map.addAll(other); return; } diff --git a/lib/src/treeset.dart b/lib/src/treeset.dart index 5aa44ba..fc0e2a9 100644 --- a/lib/src/treeset.dart +++ b/lib/src/treeset.dart @@ -393,10 +393,12 @@ class AvlTreeSet extends _BaseTreeSet { identical((items as dynamic).comparator, comparator)) { _root = items._root; return _root != null; - } - if (_root == null) { - // - var l = items.toList()..sort(comparator); + } else if (_root == null) { + var l = items.toList(); + if (items is! TreeSet || + !identical((items as dynamic).comparator, comparator)) { + l.sort(comparator); + } _root = AvlNode.fromOrderedList(l); return true; }