Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 75fc15c

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] Use cache in CommonMasks.isInterceptor
Change-Id: I8e9bf8b1c93d7bb03c3a7c4b39d603e056338270 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129310 Commit-Queue: Stephen Adams <sra@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
1 parent 84054e8 commit 75fc15c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/compiler/lib/src/inferrer/typemasks/masks.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,28 @@ class CommonMasks implements AbstractValueDomain {
756756

757757
@override
758758
AbstractBool isInterceptor(TypeMask value) {
759+
// TODO(39874): Remove cache when [TypeMask.isDisjoint] is faster.
760+
var result = _isInterceptorCache[value];
761+
if (result == null) {
762+
result = _isInterceptorCacheSecondChance[value] ?? _isInterceptor(value);
763+
if (_isInterceptorCache.length >= _kIsInterceptorCacheLimit) {
764+
_isInterceptorCacheSecondChance = _isInterceptorCache;
765+
_isInterceptorCache = {};
766+
}
767+
_isInterceptorCache[value] = result;
768+
}
769+
return result;
770+
}
771+
772+
AbstractBool _isInterceptor(TypeMask value) {
759773
return AbstractBool.maybeOrFalse(
760774
!interceptorType.isDisjoint(value, _closedWorld));
761775
}
762776

777+
static const _kIsInterceptorCacheLimit = 500;
778+
Map<TypeMask, AbstractBool> _isInterceptorCache = {};
779+
Map<TypeMask, AbstractBool> _isInterceptorCacheSecondChance = {};
780+
763781
@override
764782
bool isMap(TypeMask value) {
765783
return value.isMap;

0 commit comments

Comments
 (0)