@@ -172,15 +172,17 @@ String crossdartifySource(
172172
173173/// An UnmodifiableListView that computes equality and hashCode based on the
174174/// equality and hashCode of its contained objects.
175- class _HashableList extends UnmodifiableListView <dynamic > {
176- _HashableList (Iterable <dynamic > iterable) : super (iterable);
175+ class _HashableList {
176+ final List _source;
177+ int _hashCache;
178+ _HashableList (this ._source);
177179
178180 @override
179181 bool operator == (other) {
180182 if (other is _HashableList ) {
181- if (this .length == other.length) {
182- for (var index = 0 ; index < length; ++ index) {
183- if (this [index] != other[index]) return false ;
183+ if (_source .length == other._source .length) {
184+ for (var index = 0 ; index < _source. length; ++ index) {
185+ if (_source [index] != other._source [index]) return false ;
184186 }
185187 return true ;
186188 }
@@ -189,7 +191,7 @@ class _HashableList extends UnmodifiableListView<dynamic> {
189191 }
190192
191193 @override
192- get hashCode => hashObjects (this );
194+ get hashCode => _hashCache ?? = hashObjects (_source );
193195}
194196
195197/// Like [Memoizer] , except in checked mode will validate that the value of the
@@ -252,11 +254,11 @@ class ValidatingMemoizer extends Memoizer {
252254/// ```
253255class Memoizer {
254256 /// Map of a function and its positional parameters (if any), to a value.
255- Map <_HashableList , dynamic > _memoizationTable = new Map ();
257+ final Map <_HashableList , dynamic > _memoizationTable = new HashMap ();
256258
257259 /// Reset the memoization table, forcing calls of the underlying functions.
258260 void invalidateMemos () {
259- _memoizationTable = new Map ();
261+ _memoizationTable. clear ();
260262 }
261263
262264 /// A wrapper around putIfAbsent, exposed to allow overrides.
@@ -266,8 +268,9 @@ class Memoizer {
266268
267269 /// Calls and caches the return value of [f] () if not in the cache, then
268270 /// returns the cached value of [f] ().
269- R memoized <R >(Function f) {
270- _HashableList key = new _HashableList ([f]);
271+ R memoized <R >(Function f, {String altKey}) {
272+ Object obj = altKey ?? f;
273+ _HashableList key = new _HashableList ([obj]);
271274 return _cacheIfAbsent (key, f);
272275 }
273276
0 commit comments