From fd91c378b68229f990a95c44195c06b0c5070c94 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Sun, 12 Apr 2015 00:07:41 +0700 Subject: [PATCH] typing: shortcut `get_variable` on never-adapted variables Signed-off-by: Jean Privat --- src/semantize/typing.nit | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index ba08e4d..ee93c2e 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -444,6 +444,8 @@ private class TypeVisitor fun get_variable(node: AExpr, variable: Variable): nullable MType do + if not variable.is_adapted then return variable.declared_type + var flow = node.after_flow_context if flow == null then self.error(node, "No context!") @@ -546,6 +548,10 @@ end redef class Variable # The declared type of the variable var declared_type: nullable MType + + # Was the variable type-adapted? + # This is used to speedup type retrieval while it remains `false` + private var is_adapted = false end redef class FlowContext @@ -557,9 +563,11 @@ redef class FlowContext # Warning2: sub-flow may have cached a unadapted variable private fun set_var(v: TypeVisitor, variable: Variable, mtype: nullable MType) do + if variable.declared_type == mtype and not variable.is_adapted then return if vars.has_key(variable) and vars[variable] == mtype then return self.vars[variable] = mtype v.dirty = true + variable.is_adapted = true #node.debug "set {variable} to {mtype or else "X"}" end -- 1.7.9.5