From eb5882b4dbc6912f4b5152e605283b5d8b2ff270 Mon Sep 17 00:00:00 2001 From: Jutho Date: Sun, 25 Jan 2015 14:48:09 +0100 Subject: [PATCH] Add a cache for stagedfunctions --- base/inference.jl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/base/inference.jl b/base/inference.jl index fcb17692191d5..3569b57c1b873 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -618,11 +618,19 @@ const limit_tuple_type_n = function (t::Tuple, lim::Int) return t end -function func_for_method(m::Method, tt, env) - if !m.isstaged - return m.func.code +let stagedcache=Dict{Any,Any}() + global func_for_method + function func_for_method(m::Method, tt, env) + if !m.isstaged + return m.func.code + elseif haskey(stagedcache,(m,tt,env)) + return stagedcache[(m,tt,env)].code + else + f=ccall(:jl_instantiate_staged,Any,(Any,Any,Any),m,tt,env) + stagedcache[(m,tt,env)]=f + return f.code + end end - (ccall(:jl_instantiate_staged,Any,(Any,Any,Any),m,tt,env)).code end function abstract_call_gf(f, fargs, argtypes, e)