aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres
diff options
context:
space:
mode:
authoruHOOCCOOHu <[email protected]>2019-10-02 18:38:56 +0100
committeruHOOCCOOHu <[email protected]>2019-10-02 19:28:03 +0100
commite0100e63ae2e873f119b905ac77c3355ffb351b0 (patch)
tree25d799c1e52a32af80f603f4e6103e0969c5b6a8 /crates/ra_hir/src/nameres
parent43f09ad36ccc1c53c78a66274693e53161c9b2fa (diff)
Optimize
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r--crates/ra_hir/src/nameres/collector.rs9
-rw-r--r--crates/ra_hir/src/nameres/raw.rs11
2 files changed, 13 insertions, 7 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 1d79cbd8c..cef2dc9d2 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -7,7 +7,6 @@ use rustc_hash::FxHashMap;
7use test_utils::tested_by; 7use test_utils::tested_by;
8 8
9use crate::{ 9use crate::{
10 attr::Attr,
11 db::DefDatabase, 10 db::DefDatabase,
12 ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, 11 ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind},
13 name::MACRO_RULES, 12 name::MACRO_RULES,
@@ -715,8 +714,12 @@ where
715 } 714 }
716 } 715 }
717 716
718 fn is_cfg_enabled(&self, attrs: &[Attr]) -> bool { 717 fn is_cfg_enabled(&self, attrs: &raw::Attrs) -> bool {
719 attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) 718 attrs.as_ref().map_or(true, |attrs| {
719 attrs
720 .iter()
721 .all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false))
722 })
720 } 723 }
721} 724}
722 725
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index f02d4eb7a..623b343c4 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -120,9 +120,12 @@ impl Index<Macro> for RawItems {
120 } 120 }
121} 121}
122 122
123// Avoid heap allocation on items without attributes.
124pub(super) type Attrs = Option<Arc<[Attr]>>;
125
123#[derive(Debug, PartialEq, Eq, Clone)] 126#[derive(Debug, PartialEq, Eq, Clone)]
124pub(super) struct RawItem { 127pub(super) struct RawItem {
125 pub(super) attrs: Arc<[Attr]>, 128 pub(super) attrs: Attrs,
126 pub(super) kind: RawItemKind, 129 pub(super) kind: RawItemKind,
127} 130}
128 131
@@ -390,7 +393,7 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> {
390 fn push_import( 393 fn push_import(
391 &mut self, 394 &mut self,
392 current_module: Option<Module>, 395 current_module: Option<Module>,
393 attrs: Arc<[Attr]>, 396 attrs: Attrs,
394 data: ImportData, 397 data: ImportData,
395 source: ImportSourcePtr, 398 source: ImportSourcePtr,
396 ) { 399 ) {
@@ -399,7 +402,7 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> {
399 self.push_item(current_module, attrs, RawItemKind::Import(import)) 402 self.push_item(current_module, attrs, RawItemKind::Import(import))
400 } 403 }
401 404
402 fn push_item(&mut self, current_module: Option<Module>, attrs: Arc<[Attr]>, kind: RawItemKind) { 405 fn push_item(&mut self, current_module: Option<Module>, attrs: Attrs, kind: RawItemKind) {
403 match current_module { 406 match current_module {
404 Some(module) => match &mut self.raw_items.modules[module] { 407 Some(module) => match &mut self.raw_items.modules[module] {
405 ModuleData::Definition { items, .. } => items, 408 ModuleData::Definition { items, .. } => items,
@@ -410,7 +413,7 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> {
410 .push(RawItem { attrs, kind }) 413 .push(RawItem { attrs, kind })
411 } 414 }
412 415
413 fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Arc<[Attr]> { 416 fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs {
414 Attr::from_attrs_owner(self.file_id, item, self.db) 417 Attr::from_attrs_owner(self.file_id, item, self.db)
415 } 418 }
416} 419}