Skip to content

Commit bcf04b1

Browse files
bors[bot]Veykril
andauthored
Merge #10375
10375: minor: Use SmallVec<[_; 1]> in `descend_into_macros_impl` r=Veykril a=Veykril A lot of descends don't actually descend in which case we don't wanna allocate bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 5d4bb05 + dedc236 commit bcf04b1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

crates/hir/src/semantics.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,32 +542,32 @@ impl<'db> SemanticsImpl<'db> {
542542
None => return,
543543
};
544544
let sa = self.analyze(&parent);
545-
let mut queue = vec![InFile::new(sa.file_id, token)];
545+
let mut stack: SmallVec<[_; 1]> = smallvec![InFile::new(sa.file_id, token)];
546546
let mut cache = self.expansion_info_cache.borrow_mut();
547547

548548
let mut process_expansion_for_token =
549-
|queue: &mut Vec<_>, file_id, item, token: InFile<&_>| {
549+
|stack: &mut SmallVec<_>, file_id, item, token: InFile<&_>| {
550550
let mapped_tokens = cache
551551
.entry(file_id)
552552
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
553553
.as_ref()?
554554
.map_token_down(self.db.upcast(), item, token)?;
555555

556-
let len = queue.len();
556+
let len = stack.len();
557557
// requeue the tokens we got from mapping our current token down
558-
queue.extend(mapped_tokens.inspect(|token| {
558+
stack.extend(mapped_tokens.inspect(|token| {
559559
if let Some(parent) = token.value.parent() {
560560
self.cache(find_root(&parent), token.file_id);
561561
}
562562
}));
563563
// if the length changed we have found a mapping for the token
564-
(queue.len() != len).then(|| ())
564+
(stack.len() != len).then(|| ())
565565
};
566566

567567
// Remap the next token in the queue into a macro call its in, if it is not being remapped
568568
// either due to not being in a macro-call or because its unused push it into the result vec,
569569
// otherwise push the remapped tokens back into the queue as they can potentially be remapped again.
570-
while let Some(token) = queue.pop() {
570+
while let Some(token) = stack.pop() {
571571
self.db.unwind_if_cancelled();
572572
let was_not_remapped = (|| {
573573
// are we inside an attribute macro call
@@ -584,7 +584,7 @@ impl<'db> SemanticsImpl<'db> {
584584
if let Some((call_id, item)) = containing_attribute_macro_call {
585585
let file_id = call_id.as_file();
586586
return process_expansion_for_token(
587-
&mut queue,
587+
&mut stack,
588588
file_id,
589589
Some(item),
590590
token.as_ref(),
@@ -607,7 +607,7 @@ impl<'db> SemanticsImpl<'db> {
607607
}
608608

609609
let file_id = sa.expand(self.db, token.with_value(&macro_call))?;
610-
return process_expansion_for_token(&mut queue, file_id, None, token.as_ref());
610+
return process_expansion_for_token(&mut stack, file_id, None, token.as_ref());
611611
}
612612

613613
// outside of a macro invocation so this is a "final" token

0 commit comments

Comments
 (0)