You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Vupdate(K key, Vupdate(V value), {VFunction()? ifAbsent}) {
if (this.containsKey(key)) {
returnthis[key] =update(this[key] asV);
}
if (ifAbsent !=null) {
returnthis[key] =ifAbsent();
}
throwArgumentError.value(key, "key", "Key not in map.");
}
This performs 3 lookups into the map. The map implementations should override their update implementations to be faster:
classHashMap<K, V> {
@overrideVupdate(K key, Vupdate(V value), {VFunction()? ifAbsent}) {
final hashCode = key.hashCode;
final buckets = _buckets;
final length = buckets.length;
final index = hashCode & (length -1);
var entry = buckets[index];
while (entry !=null) {
if (hashCode == entry.hashCode && entry.key == key) {
entry.value =update(value);
return;
}
entry = entry.next;
}
if (ifAbsent !=null) {
_addEntry(buckets, index, length, key, ifAbsent(), hashCode);
}
throwArgumentError.value(key, "key", "Key not in map.");
}
}
In local benchmarks the current HashMap.update implementation is ~2x slower than just using x[y] = x[y] + 1. In SplayTreeMap it's ~40% faster to use update because it does update in one pass.
The text was updated successfully, but these errors were encountered:
This tracker is for issues related to:
Map.update is implemented as:
This performs 3 lookups into the map. The map implementations should override their
update
implementations to be faster:In local benchmarks the current
HashMap.update
implementation is ~2x slower than just usingx[y] = x[y] + 1
. In SplayTreeMap it's ~40% faster to useupdate
because it doesupdate
in one pass.The text was updated successfully, but these errors were encountered: