Skip to content

Commit

Permalink
Avoid unnecessary clone
Browse files Browse the repository at this point in the history
  • Loading branch information
ebresafegaga committed Mar 27, 2023
1 parent 4dce01a commit 5c4453e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lsp/nls/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use codespan::FileId;
use nickel_lang::{
cache::{Cache, CacheError, CacheOp, CachedTerm, EntryState},
error::{Error, ImportError},
position::TermPos,
term::{RichTerm, Term, Traverse, TraverseOrder},
typecheck::{self, linearization::Linearization},
};
Expand Down Expand Up @@ -58,12 +57,16 @@ impl CacheExt for Cache {
}

// After self.parse(), the cache must be populated
let CachedTerm { term, .. } = self.terms().get(&file_id).unwrap();
let mut errors: Vec<(String, TermPos)> = Vec::new();
let CachedTerm {
term,
state,
parse_errs,
} = self.terms_mut().remove(&file_id).unwrap();

let term = term.clone(); // Don't like this

term.traverse::<_, _, ()>(
// We do this to get a list of the imports that have been resolved
// but don't typecheck, and output an appriopiate diagnostics
let mut errors = Vec::new();
let term = term.traverse::<_, _, ()>(
// O(n) every time
&|rt, errors: &mut Vec<_>| {
let RichTerm { ref term, pos } = rt;
Expand All @@ -81,6 +84,15 @@ impl CacheExt for Cache {
)
.unwrap();

self.terms_mut().insert(
file_id,
CachedTerm {
term,
state,
parse_errs,
},
);

let message = "This import could not be resolved because its content either failed to parse or typecheck correctly.";
let errors = errors
.into_iter()
Expand Down

0 comments on commit 5c4453e

Please sign in to comment.