1
Fork 0

resolve: improve/remove allocations

This commit is contained in:
ljedrz 2018-10-17 11:36:19 +02:00
parent da40916bc2
commit 89c20b78d6
2 changed files with 8 additions and 19 deletions

View file

@ -3021,10 +3021,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
let mut err = this.session.struct_span_err_with_code(base_span, &base_msg, code); let mut err = this.session.struct_span_err_with_code(base_span, &base_msg, code);
// Emit help message for fake-self from other languages like `this`(javascript) // Emit help message for fake-self from other languages like `this`(javascript)
let fake_self: Vec<Ident> = ["this", "my"].iter().map( if ["this", "my"].contains(&&*item_str.as_str())
|s| Ident::from_str(*s)
).collect();
if fake_self.contains(&item_str)
&& this.self_value_is_available(path[0].span, span) { && this.self_value_is_available(path[0].span, span) {
err.span_suggestion_with_applicability( err.span_suggestion_with_applicability(
span, span,
@ -4377,10 +4374,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
where FilterFn: Fn(Def) -> bool where FilterFn: Fn(Def) -> bool
{ {
let mut candidates = Vec::new(); let mut candidates = Vec::new();
let mut worklist = Vec::new();
let mut seen_modules = FxHashSet(); let mut seen_modules = FxHashSet();
let not_local_module = crate_name != keywords::Crate.ident(); let not_local_module = crate_name != keywords::Crate.ident();
worklist.push((start_module, Vec::<ast::PathSegment>::new(), not_local_module)); let mut worklist = vec![(start_module, Vec::<ast::PathSegment>::new(), not_local_module)];
while let Some((in_module, while let Some((in_module,
path_segments, path_segments,
@ -4467,13 +4463,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
-> Vec<ImportSuggestion> -> Vec<ImportSuggestion>
where FilterFn: Fn(Def) -> bool where FilterFn: Fn(Def) -> bool
{ {
let mut suggestions = vec![]; let mut suggestions = self.lookup_import_candidates_from_module(
lookup_name, namespace, self.graph_root, keywords::Crate.ident(), &filter_fn);
suggestions.extend(
self.lookup_import_candidates_from_module(
lookup_name, namespace, self.graph_root, keywords::Crate.ident(), &filter_fn
)
);
if self.session.rust_2018() { if self.session.rust_2018() {
let extern_prelude_names = self.extern_prelude.clone(); let extern_prelude_names = self.extern_prelude.clone();
@ -4502,9 +4493,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
-> Option<(Module<'a>, ImportSuggestion)> -> Option<(Module<'a>, ImportSuggestion)>
{ {
let mut result = None; let mut result = None;
let mut worklist = Vec::new();
let mut seen_modules = FxHashSet(); let mut seen_modules = FxHashSet();
worklist.push((self.graph_root, Vec::new())); let mut worklist = vec![(self.graph_root, Vec::new())];
while let Some((in_module, path_segments)) = worklist.pop() { while let Some((in_module, path_segments)) = worklist.pop() {
// abort if the module is already found // abort if the module is already found

View file

@ -203,9 +203,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
self.current_module = invocation.module.get(); self.current_module = invocation.module.get();
self.current_module.unresolved_invocations.borrow_mut().remove(&mark); self.current_module.unresolved_invocations.borrow_mut().remove(&mark);
self.current_module.unresolved_invocations.borrow_mut().extend(derives); self.current_module.unresolved_invocations.borrow_mut().extend(derives);
for &derive in derives { self.invocations.extend(derives.iter().map(|&derive| (derive, invocation)));
self.invocations.insert(derive, invocation);
}
let mut visitor = BuildReducedGraphVisitor { let mut visitor = BuildReducedGraphVisitor {
resolver: self, resolver: self,
current_legacy_scope: invocation.parent_legacy_scope.get(), current_legacy_scope: invocation.parent_legacy_scope.get(),
@ -277,11 +275,12 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
if traits.is_empty() { if traits.is_empty() {
attrs.remove(i); attrs.remove(i);
} else { } else {
let mut tokens = Vec::new(); let mut tokens = Vec::with_capacity(traits.len() - 1);
for (j, path) in traits.iter().enumerate() { for (j, path) in traits.iter().enumerate() {
if j > 0 { if j > 0 {
tokens.push(TokenTree::Token(attrs[i].span, Token::Comma).into()); tokens.push(TokenTree::Token(attrs[i].span, Token::Comma).into());
} }
tokens.reserve((path.segments.len() * 2).saturating_sub(1));
for (k, segment) in path.segments.iter().enumerate() { for (k, segment) in path.segments.iter().enumerate() {
if k > 0 { if k > 0 {
tokens.push(TokenTree::Token(path.span, Token::ModSep).into()); tokens.push(TokenTree::Token(path.span, Token::ModSep).into());