Skip to content

Commit 762efdf

Browse files
committed
Ditch the unnecessary smallvec
1 parent e51cad9 commit 762efdf

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use hir_expand::{
5353
use intern::Interned;
5454
use la_arena::Idx;
5555
use rustc_hash::FxHashMap;
56-
use smallvec::SmallVec;
5756
use span::{AstIdNode, Edition, ErasedFileAstId, FileAstId, SyntaxContext};
5857
use stdx::never;
5958
use syntax::{SyntaxKind, ast, match_ast};
@@ -89,11 +88,12 @@ impl fmt::Debug for RawVisibilityId {
8988
/// The item tree of a source file.
9089
#[derive(Debug, Default, Eq, PartialEq)]
9190
pub struct ItemTree {
92-
top_level: SmallVec<[ModItemId; 1]>,
91+
top_level: Box<[ModItemId]>,
9392
// Consider splitting this into top level RawAttrs and the map?
9493
attrs: FxHashMap<AttrOwner, RawAttrs>,
9594

9695
vis: ItemVisibilities,
96+
// FIXME: They values store the key, turn this into a FxHashSet<ModItem> instead?
9797
data: FxHashMap<FileAstId<ast::Item>, ModItem>,
9898
}
9999

@@ -136,7 +136,7 @@ impl ItemTree {
136136
EMPTY
137137
.get_or_init(|| {
138138
Arc::new(ItemTree {
139-
top_level: SmallVec::new_const(),
139+
top_level: Box::new([]),
140140
attrs: FxHashMap::default(),
141141
data: FxHashMap::default(),
142142
vis: ItemVisibilities { arena: Box::new([]) },
@@ -163,7 +163,7 @@ impl ItemTree {
163163
EMPTY
164164
.get_or_init(|| {
165165
Arc::new(ItemTree {
166-
top_level: SmallVec::new_const(),
166+
top_level: Box::new([]),
167167
attrs: FxHashMap::default(),
168168
data: FxHashMap::default(),
169169
vis: ItemVisibilities { arena: Box::new([]) },
@@ -226,8 +226,7 @@ impl ItemTree {
226226
}
227227

228228
fn shrink_to_fit(&mut self) {
229-
let ItemTree { top_level, attrs, data, vis: _ } = self;
230-
top_level.shrink_to_fit();
229+
let ItemTree { top_level: _, attrs, data, vis: _ } = self;
231230
attrs.shrink_to_fit();
232231
data.shrink_to_fit();
233232
}

src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub(super) struct Ctx<'a> {
3333
source_ast_id_map: Arc<AstIdMap>,
3434
span_map: OnceCell<SpanMap>,
3535
file: HirFileId,
36+
top_level: Vec<ModItemId>,
3637
visibilities: FxIndexSet<RawVisibility>,
3738
}
3839

@@ -45,6 +46,7 @@ impl<'a> Ctx<'a> {
4546
file,
4647
span_map: OnceCell::new(),
4748
visibilities: FxIndexSet::default(),
49+
top_level: Vec::new(),
4850
}
4951
}
5052

@@ -53,14 +55,14 @@ impl<'a> Ctx<'a> {
5355
}
5456

5557
pub(super) fn lower_module_items(mut self, item_owner: &dyn HasModuleItem) -> ItemTree {
56-
self.tree.top_level =
57-
item_owner.items().flat_map(|item| self.lower_mod_item(&item)).collect();
58+
self.top_level = item_owner.items().flat_map(|item| self.lower_mod_item(&item)).collect();
5859
self.tree.vis.arena = self.visibilities.into_iter().collect();
60+
self.tree.top_level = self.top_level.into_boxed_slice();
5961
self.tree
6062
}
6163

6264
pub(super) fn lower_macro_stmts(mut self, stmts: ast::MacroStmts) -> ItemTree {
63-
self.tree.top_level = stmts
65+
self.top_level = stmts
6466
.statements()
6567
.filter_map(|stmt| {
6668
match stmt {
@@ -84,18 +86,19 @@ impl<'a> Ctx<'a> {
8486
if let Some(call) = tail_macro.macro_call() {
8587
cov_mark::hit!(macro_stmt_with_trailing_macro_expr);
8688
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
87-
self.tree.top_level.push(mod_item);
89+
self.top_level.push(mod_item);
8890
}
8991
}
9092
}
9193

9294
self.tree.vis.arena = self.visibilities.into_iter().collect();
95+
self.tree.top_level = self.top_level.into_boxed_slice();
9396
self.tree
9497
}
9598

9699
pub(super) fn lower_block(mut self, block: &ast::BlockExpr) -> ItemTree {
97100
self.tree.attrs.insert(AttrOwner::TopLevel, RawAttrs::new(self.db, block, self.span_map()));
98-
self.tree.top_level = block
101+
self.top_level = block
99102
.statements()
100103
.filter_map(|stmt| match stmt {
101104
ast::Stmt::Item(item) => self.lower_mod_item(&item),
@@ -111,11 +114,12 @@ impl<'a> Ctx<'a> {
111114
if let Some(ast::Expr::MacroExpr(expr)) = block.tail_expr() {
112115
if let Some(call) = expr.macro_call() {
113116
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
114-
self.tree.top_level.push(mod_item);
117+
self.top_level.push(mod_item);
115118
}
116119
}
117120
}
118121
self.tree.vis.arena = self.visibilities.into_iter().collect();
122+
self.tree.top_level = self.top_level.into_boxed_slice();
119123
self.tree
120124
}
121125

0 commit comments

Comments
 (0)