mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Add cached for SubtreeSource
This commit is contained in:
parent
c416caeda2
commit
fccd045229
1 changed files with 20 additions and 4 deletions
|
@ -219,17 +219,33 @@ pub(crate) trait Querier {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct WalkerOwner<'a> {
|
pub(crate) struct WalkerOwner<'a> {
|
||||||
walker: RefCell<SubTreeWalker<'a>>,
|
walker: RefCell<SubTreeWalker<'a>>,
|
||||||
|
cached: RefCell<Vec<Option<TtToken>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> WalkerOwner<'a> {
|
impl<'a> WalkerOwner<'a> {
|
||||||
fn new<I: Into<TokenSeq<'a>>>(ts: I) -> Self {
|
fn new<I: Into<TokenSeq<'a>>>(ts: I) -> Self {
|
||||||
WalkerOwner { walker: RefCell::new(SubTreeWalker::new(ts.into())) }
|
WalkerOwner {
|
||||||
|
walker: RefCell::new(SubTreeWalker::new(ts.into())),
|
||||||
|
cached: RefCell::new(Vec::with_capacity(10)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get<'b>(&self, pos: usize) -> Option<TtToken> {
|
fn get<'b>(&self, pos: usize) -> Option<TtToken> {
|
||||||
self.set_pos(pos);
|
let mut cached = self.cached.borrow_mut();
|
||||||
|
if pos < cached.len() {
|
||||||
|
return cached[pos].clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
while pos >= cached.len() {
|
||||||
|
let len = cached.len();
|
||||||
|
cached.push({
|
||||||
|
self.set_pos(len);
|
||||||
let walker = self.walker.borrow();
|
let walker = self.walker.borrow();
|
||||||
walker.current().cloned()
|
walker.current().cloned()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return cached[pos].clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_pos(&self, pos: usize) {
|
fn set_pos(&self, pos: usize) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue