Skip to content

Commit

Permalink
perf: improve speed of FilteredMapView.completeInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
rbellens committed Feb 28, 2024
1 parent 1e771fe commit 14dad5b
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions lib/src/filteredmap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ abstract class FilteredMap<K extends Comparable, V> implements SortedMap<K, V> {
/// The interval within which no values were filtered out based on the
/// filter's `limit` or `validInterval`.
KeyValueInterval get completeInterval {
var entries = this.entries;
var filterInterval = filter.validInterval;
if (filter.limit == null || length < filter.limit!) {
if (filter.limit == null || entries.length < filter.limit!) {
return filterInterval;
}
if (filter.limit == 0) return KeyValueInterval();
Expand Down Expand Up @@ -148,18 +149,7 @@ class FilteredMapView<K extends Comparable, V> extends MapBase<K, V>

@override
int get length {
var b = _baseMap;
if (b is _SortedMap<K, V>) {
var e = (b._sortedEntries as AvlTreeSet<_MapEntryWithIndex<K, V>>)
.countUntil(_MapEntryWithIndex.indexOnly(filter.validInterval.end),
inclusive: true);
var s = (b._sortedEntries as AvlTreeSet<_MapEntryWithIndex<K, V>>)
.countUntil(_MapEntryWithIndex.indexOnly(filter.validInterval.start),
inclusive: false);
var total = e - s;
return filter.limit == null ? total : min(total, filter.limit!);
}
return super.length;
return entries.length;
}

@override
Expand Down

0 comments on commit 14dad5b

Please sign in to comment.