@@ -172,15 +172,17 @@ String crossdartifySource(
172
172
173
173
/// An UnmodifiableListView that computes equality and hashCode based on the
174
174
/// 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);
177
179
178
180
@override
179
181
bool operator == (other) {
180
182
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 ;
184
186
}
185
187
return true ;
186
188
}
@@ -189,7 +191,7 @@ class _HashableList extends UnmodifiableListView<dynamic> {
189
191
}
190
192
191
193
@override
192
- get hashCode => hashObjects (this );
194
+ get hashCode => _hashCache ?? = hashObjects (_source );
193
195
}
194
196
195
197
/// Like [Memoizer] , except in checked mode will validate that the value of the
@@ -252,11 +254,11 @@ class ValidatingMemoizer extends Memoizer {
252
254
/// ```
253
255
class Memoizer {
254
256
/// 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 ();
256
258
257
259
/// Reset the memoization table, forcing calls of the underlying functions.
258
260
void invalidateMemos () {
259
- _memoizationTable = new Map ();
261
+ _memoizationTable. clear ();
260
262
}
261
263
262
264
/// A wrapper around putIfAbsent, exposed to allow overrides.
@@ -266,8 +268,9 @@ class Memoizer {
266
268
267
269
/// Calls and caches the return value of [f] () if not in the cache, then
268
270
/// 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]);
271
274
return _cacheIfAbsent (key, f);
272
275
}
273
276
0 commit comments