mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 02:52:11 +00:00
Ditch the unnecessary smallvec
This commit is contained in:
parent
8930c58d30
commit
f27268f319
2 changed files with 15 additions and 12 deletions
|
|
@ -53,7 +53,6 @@ use hir_expand::{
|
||||||
use intern::Interned;
|
use intern::Interned;
|
||||||
use la_arena::Idx;
|
use la_arena::Idx;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use smallvec::SmallVec;
|
|
||||||
use span::{AstIdNode, Edition, ErasedFileAstId, FileAstId, SyntaxContext};
|
use span::{AstIdNode, Edition, ErasedFileAstId, FileAstId, SyntaxContext};
|
||||||
use stdx::never;
|
use stdx::never;
|
||||||
use syntax::{SyntaxKind, ast, match_ast};
|
use syntax::{SyntaxKind, ast, match_ast};
|
||||||
|
|
@ -89,11 +88,12 @@ impl fmt::Debug for RawVisibilityId {
|
||||||
/// The item tree of a source file.
|
/// The item tree of a source file.
|
||||||
#[derive(Debug, Default, Eq, PartialEq)]
|
#[derive(Debug, Default, Eq, PartialEq)]
|
||||||
pub struct ItemTree {
|
pub struct ItemTree {
|
||||||
top_level: SmallVec<[ModItemId; 1]>,
|
top_level: Box<[ModItemId]>,
|
||||||
// Consider splitting this into top level RawAttrs and the map?
|
// Consider splitting this into top level RawAttrs and the map?
|
||||||
attrs: FxHashMap<AttrOwner, RawAttrs>,
|
attrs: FxHashMap<AttrOwner, RawAttrs>,
|
||||||
|
|
||||||
vis: ItemVisibilities,
|
vis: ItemVisibilities,
|
||||||
|
// FIXME: They values store the key, turn this into a FxHashSet<ModItem> instead?
|
||||||
data: FxHashMap<FileAstId<ast::Item>, ModItem>,
|
data: FxHashMap<FileAstId<ast::Item>, ModItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ impl ItemTree {
|
||||||
EMPTY
|
EMPTY
|
||||||
.get_or_init(|| {
|
.get_or_init(|| {
|
||||||
Arc::new(ItemTree {
|
Arc::new(ItemTree {
|
||||||
top_level: SmallVec::new_const(),
|
top_level: Box::new([]),
|
||||||
attrs: FxHashMap::default(),
|
attrs: FxHashMap::default(),
|
||||||
data: FxHashMap::default(),
|
data: FxHashMap::default(),
|
||||||
vis: ItemVisibilities { arena: Box::new([]) },
|
vis: ItemVisibilities { arena: Box::new([]) },
|
||||||
|
|
@ -163,7 +163,7 @@ impl ItemTree {
|
||||||
EMPTY
|
EMPTY
|
||||||
.get_or_init(|| {
|
.get_or_init(|| {
|
||||||
Arc::new(ItemTree {
|
Arc::new(ItemTree {
|
||||||
top_level: SmallVec::new_const(),
|
top_level: Box::new([]),
|
||||||
attrs: FxHashMap::default(),
|
attrs: FxHashMap::default(),
|
||||||
data: FxHashMap::default(),
|
data: FxHashMap::default(),
|
||||||
vis: ItemVisibilities { arena: Box::new([]) },
|
vis: ItemVisibilities { arena: Box::new([]) },
|
||||||
|
|
@ -226,8 +226,7 @@ impl ItemTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shrink_to_fit(&mut self) {
|
fn shrink_to_fit(&mut self) {
|
||||||
let ItemTree { top_level, attrs, data, vis: _ } = self;
|
let ItemTree { top_level: _, attrs, data, vis: _ } = self;
|
||||||
top_level.shrink_to_fit();
|
|
||||||
attrs.shrink_to_fit();
|
attrs.shrink_to_fit();
|
||||||
data.shrink_to_fit();
|
data.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ pub(super) struct Ctx<'a> {
|
||||||
source_ast_id_map: Arc<AstIdMap>,
|
source_ast_id_map: Arc<AstIdMap>,
|
||||||
span_map: OnceCell<SpanMap>,
|
span_map: OnceCell<SpanMap>,
|
||||||
file: HirFileId,
|
file: HirFileId,
|
||||||
|
top_level: Vec<ModItemId>,
|
||||||
visibilities: FxIndexSet<RawVisibility>,
|
visibilities: FxIndexSet<RawVisibility>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,6 +46,7 @@ impl<'a> Ctx<'a> {
|
||||||
file,
|
file,
|
||||||
span_map: OnceCell::new(),
|
span_map: OnceCell::new(),
|
||||||
visibilities: FxIndexSet::default(),
|
visibilities: FxIndexSet::default(),
|
||||||
|
top_level: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,14 +55,14 @@ impl<'a> Ctx<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn lower_module_items(mut self, item_owner: &dyn HasModuleItem) -> ItemTree {
|
pub(super) fn lower_module_items(mut self, item_owner: &dyn HasModuleItem) -> ItemTree {
|
||||||
self.tree.top_level =
|
self.top_level = item_owner.items().flat_map(|item| self.lower_mod_item(&item)).collect();
|
||||||
item_owner.items().flat_map(|item| self.lower_mod_item(&item)).collect();
|
|
||||||
self.tree.vis.arena = self.visibilities.into_iter().collect();
|
self.tree.vis.arena = self.visibilities.into_iter().collect();
|
||||||
|
self.tree.top_level = self.top_level.into_boxed_slice();
|
||||||
self.tree
|
self.tree
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn lower_macro_stmts(mut self, stmts: ast::MacroStmts) -> ItemTree {
|
pub(super) fn lower_macro_stmts(mut self, stmts: ast::MacroStmts) -> ItemTree {
|
||||||
self.tree.top_level = stmts
|
self.top_level = stmts
|
||||||
.statements()
|
.statements()
|
||||||
.filter_map(|stmt| {
|
.filter_map(|stmt| {
|
||||||
match stmt {
|
match stmt {
|
||||||
|
|
@ -84,18 +86,19 @@ impl<'a> Ctx<'a> {
|
||||||
if let Some(call) = tail_macro.macro_call() {
|
if let Some(call) = tail_macro.macro_call() {
|
||||||
cov_mark::hit!(macro_stmt_with_trailing_macro_expr);
|
cov_mark::hit!(macro_stmt_with_trailing_macro_expr);
|
||||||
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
|
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
|
||||||
self.tree.top_level.push(mod_item);
|
self.top_level.push(mod_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.tree.vis.arena = self.visibilities.into_iter().collect();
|
self.tree.vis.arena = self.visibilities.into_iter().collect();
|
||||||
|
self.tree.top_level = self.top_level.into_boxed_slice();
|
||||||
self.tree
|
self.tree
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn lower_block(mut self, block: &ast::BlockExpr) -> ItemTree {
|
pub(super) fn lower_block(mut self, block: &ast::BlockExpr) -> ItemTree {
|
||||||
self.tree.attrs.insert(AttrOwner::TopLevel, RawAttrs::new(self.db, block, self.span_map()));
|
self.tree.attrs.insert(AttrOwner::TopLevel, RawAttrs::new(self.db, block, self.span_map()));
|
||||||
self.tree.top_level = block
|
self.top_level = block
|
||||||
.statements()
|
.statements()
|
||||||
.filter_map(|stmt| match stmt {
|
.filter_map(|stmt| match stmt {
|
||||||
ast::Stmt::Item(item) => self.lower_mod_item(&item),
|
ast::Stmt::Item(item) => self.lower_mod_item(&item),
|
||||||
|
|
@ -111,11 +114,12 @@ impl<'a> Ctx<'a> {
|
||||||
if let Some(ast::Expr::MacroExpr(expr)) = block.tail_expr() {
|
if let Some(ast::Expr::MacroExpr(expr)) = block.tail_expr() {
|
||||||
if let Some(call) = expr.macro_call() {
|
if let Some(call) = expr.macro_call() {
|
||||||
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
|
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
|
||||||
self.tree.top_level.push(mod_item);
|
self.top_level.push(mod_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.tree.vis.arena = self.visibilities.into_iter().collect();
|
self.tree.vis.arena = self.visibilities.into_iter().collect();
|
||||||
|
self.tree.top_level = self.top_level.into_boxed_slice();
|
||||||
self.tree
|
self.tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue