@@ -116,6 +116,7 @@ class NaiveInterpreter
116
116
fun clear_caches
117
117
do
118
118
anchor_to_cache .clear
119
+ lookup_first_definition_cache .clear
119
120
end
120
121
121
122
# Subtype test in the context of the mainmodule
@@ -645,10 +646,23 @@ class NaiveInterpreter
645
646
var mtype = recv .mtype
646
647
var ret = send_commons (mproperty , args , mtype )
647
648
if ret != null then return ret
648
- var propdef = mproperty . lookup_first_definition (self . mainmodule , mtype )
649
+ var propdef = lookup_first_definition (mtype , mproperty )
649
650
return self .call (propdef , args )
650
651
end
651
652
653
+ private var lookup_first_definition_cache = new HashMap2 [MType , MMethod , MMethodDef ]
654
+
655
+ # Cached version of lookup_first_definition for the main module
656
+ fun lookup_first_definition (mtype : MType , mproperty : MMethod ): MMethodDef
657
+ do
658
+ if mproperty .mpropdefs .length == 1 then return mproperty .mpropdefs .first
659
+ var res = lookup_first_definition_cache [mtype , mproperty ]
660
+ if res != null then return res
661
+ res = mproperty .lookup_first_definition (self .mainmodule , mtype )
662
+ lookup_first_definition_cache [mtype , mproperty ] = res
663
+ return res
664
+ end
665
+
652
666
# Read the attribute `mproperty` of an instance `recv` and return its value.
653
667
# If the attribute in not yet initialized, then aborts with an error message.
654
668
fun read_attribute (mproperty : MAttribute , recv : Instance ): Instance
0 commit comments