Skip to content

Commit

Permalink
perf: addAll to empty SortedMap from FilteredMapView
Browse files Browse the repository at this point in the history
  • Loading branch information
rbellens committed Apr 22, 2024
1 parent 9ef6e1b commit d889953
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/src/sortedmap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ class _SortedMap<K extends Comparable, V> extends MapBase<K, V>
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<K, V>>) {
entries = entries.map<_MapEntryWithIndex<K, V>>(
(e) => ordering.mapEntry(e.key, e.value));
}
_sortedEntries.addAll(entries);
_map.addAll(other);
return;
}
Expand Down
10 changes: 6 additions & 4 deletions lib/src/treeset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,12 @@ class AvlTreeSet<V> extends _BaseTreeSet<V> {
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<V> ||
!identical((items as dynamic).comparator, comparator)) {
l.sort(comparator);
}
_root = AvlNode.fromOrderedList(l);
return true;
}
Expand Down

0 comments on commit d889953

Please sign in to comment.