From ee4b5a34d8aa789ebc521926123fba79eebe5981 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 3 Apr 2021 20:58:42 +0200 Subject: Use bitflags to compress function properties Very minor savings, only 1 MB or so --- crates/hir/src/display.rs | 17 ++++++++--------- crates/hir/src/lib.rs | 6 +++--- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index ab04c55bc..559ea31a0 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -20,22 +20,21 @@ impl HirDisplay for Function { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { let data = f.db.function_data(self.id); write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; - let qual = &data.qualifier; - if qual.is_default { + if data.is_default() { write!(f, "default ")?; } - if qual.is_const { + if data.is_const() { write!(f, "const ")?; } - if qual.is_async { + if data.is_async() { write!(f, "async ")?; } - if qual.is_unsafe { + if data.is_unsafe() { write!(f, "unsafe ")?; } - if let Some(abi) = &qual.abi { + if let Some(abi) = &data.abi { // FIXME: String escape? - write!(f, "extern \"{}\" ", abi)?; + write!(f, "extern \"{}\" ", &**abi)?; } write!(f, "fn {}", data.name)?; @@ -68,7 +67,7 @@ impl HirDisplay for Function { write!(f, ", ")?; } else { first = false; - if data.has_self_param { + if data.has_self_param() { write_self_param(type_ref, f)?; continue; } @@ -88,7 +87,7 @@ impl HirDisplay for Function { // `FunctionData::ret_type` will be `::core::future::Future` for async fns. // Use ugly pattern match to strip the Future trait. // Better way? - let ret_type = if !qual.is_async { + let ret_type = if !data.is_async() { &data.ret_type } else { match &*data.ret_type { diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 29010191b..eb19e4b51 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -832,7 +832,7 @@ impl Function { } pub fn self_param(self, db: &dyn HirDatabase) -> Option { - if !db.function_data(self.id).has_self_param { + if !db.function_data(self.id).has_self_param() { return None; } Some(SelfParam { func: self.id }) @@ -864,7 +864,7 @@ impl Function { } pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool { - db.function_data(self.id).qualifier.is_unsafe + db.function_data(self.id).is_unsafe() } pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { @@ -878,7 +878,7 @@ impl Function { /// /// This is false in the case of required (not provided) trait methods. pub fn has_body(self, db: &dyn HirDatabase) -> bool { - db.function_data(self.id).has_body + db.function_data(self.id).has_body() } /// A textual representation of the HIR of this function for debugging purposes. -- cgit v1.2.3