Pass a dummy isValidKey callback to normalized map and set

The default implementation runs a type check, which was a performance
bottleneck when compiled to JS. There's no need for this type check in
practice, since we never pass a non-String value to the contains(),
containsKey(), or remove() methods (and if we do, it will throw a
TypeError in our tests).
This commit is contained in:
Natalie Weizenbaum 2019-07-12 13:14:28 -07:00
parent a841882724
commit a8e99e9152

View File

@ -306,7 +306,11 @@ bool startsWithIgnoreSeparator(String string, String prefix) {
/// If [source] is passed, copies it into the map.
Map<String, V> normalizedMap<V>([Map<String, V> source]) {
var map = LinkedHashMap<String, V>(
equals: equalsIgnoreSeparator, hashCode: hashCodeIgnoreSeparator);
// Explicitly set this because the default implementation involves a type
// check, which is very expensive in dart2js.
isValidKey: (_) => true,
equals: equalsIgnoreSeparator,
hashCode: hashCodeIgnoreSeparator);
if (source != null) map.addAll(source);
return map;
}
@ -316,7 +320,11 @@ Map<String, V> normalizedMap<V>([Map<String, V> source]) {
/// If [source] is passed, copies it into the set.
Set<String> normalizedSet([Iterable<String> source]) {
var set = LinkedHashSet(
equals: equalsIgnoreSeparator, hashCode: hashCodeIgnoreSeparator);
// Explicitly set this because the default implementation involves a type
// check, which is very expensive in dart2js.
isValidKey: (_) => true,
equals: equalsIgnoreSeparator,
hashCode: hashCodeIgnoreSeparator);
if (source != null) set.addAll(source);
return set;
}