From b36ade1367a2dbca69386b58d225ceafa6a90d57 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sun, 18 Dec 2011 19:07:26 +0100 Subject: [PATCH] Improve efficienty of impl cache in resolve And fix a bug where importing anything from an external module would import all impls in the module. Issue #1227 --- src/comp/middle/resolve.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index b0b3c02db00..c00bd711eb0 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -1717,22 +1717,27 @@ fn find_impls_in_mod(e: env, m: def, &impls: [@_impl], name: option::t) { alt m { ast::def_mod(defid) { + let cached; alt e.impl_cache.find(defid) { - some(v) { impls += *v; } + some(v) { cached = v; } none. { - let found = []; - if defid.crate == ast::local_crate { - let md = option::get(e.mod_map.get(defid.node).m); - for i in md.items { - find_impls_in_item(i, found, name, some(md)); + cached = if defid.crate == ast::local_crate { + let tmp = []; + for i in option::get(e.mod_map.get(defid.node).m).items { + find_impls_in_item(i, tmp, name, none); } + @tmp } else { - found = csearch::get_impls_for_mod(e.cstore, defid, name); - } - impls += found; - e.impl_cache.insert(defid, @found); + @csearch::get_impls_for_mod(e.cstore, defid, name) + }; + e.impl_cache.insert(defid, cached); } } + for im in *cached { + if alt name { some(n) { n == im.ident } _ { true } } { + impls += [im]; + } + } } _ {} }