perf: add #[inline] attribute to getters

This commit is contained in:
Rolo 2024-12-30 10:10:38 -08:00
parent 1eda83e3e5
commit 7a368fcc58

View file

@ -48,105 +48,156 @@ pub struct Lsp {
impl Lsp { impl Lsp {
const DEFAULT: &'static str = "*"; const DEFAULT: &'static str = "*";
#[inline]
pub fn file(&self) -> &str { pub fn file(&self) -> &str {
self.file.as_ref().map_or(Self::DEFAULT, |file| file) self.file.as_ref().map_or(Self::DEFAULT, |file| file)
} }
#[inline]
pub fn module(&self) -> &str { pub fn module(&self) -> &str {
self.module.as_ref().map_or(Self::DEFAULT, |module| module) self.module.as_ref().map_or(Self::DEFAULT, |module| module)
} }
#[inline]
pub fn namespace(&self) -> &str { pub fn namespace(&self) -> &str {
self.namespace self.namespace
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |namespace| namespace) .map_or(Self::DEFAULT, |namespace| namespace)
} }
#[inline]
pub fn package(&self) -> &str { pub fn package(&self) -> &str {
self.package self.package
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |package| package) .map_or(Self::DEFAULT, |package| package)
} }
#[inline]
pub fn class(&self) -> &str { pub fn class(&self) -> &str {
self.class.as_ref().map_or(Self::DEFAULT, |class| class) self.class.as_ref().map_or(Self::DEFAULT, |class| class)
} }
#[inline]
pub fn method(&self) -> &str { pub fn method(&self) -> &str {
self.method.as_ref().map_or(Self::DEFAULT, |method| method) self.method.as_ref().map_or(Self::DEFAULT, |method| method)
} }
#[inline]
pub fn property(&self) -> &str { pub fn property(&self) -> &str {
self.property self.property
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |property| property) .map_or(Self::DEFAULT, |property| property)
} }
#[inline]
pub fn field(&self) -> &str { pub fn field(&self) -> &str {
self.field.as_ref().map_or(Self::DEFAULT, |field| field) self.field.as_ref().map_or(Self::DEFAULT, |field| field)
} }
#[inline]
pub fn constructor(&self) -> &str { pub fn constructor(&self) -> &str {
self.constructor self.constructor
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |constructor| constructor) .map_or(Self::DEFAULT, |constructor| constructor)
} }
#[inline]
pub fn r#enum(&self) -> &str { pub fn r#enum(&self) -> &str {
self.r#enum.as_ref().map_or(Self::DEFAULT, |r#enum| r#enum) self.r#enum.as_ref().map_or(Self::DEFAULT, |r#enum| r#enum)
} }
#[inline]
pub fn interface(&self) -> &str { pub fn interface(&self) -> &str {
self.interface self.interface
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |interface| interface) .map_or(Self::DEFAULT, |interface| interface)
} }
#[inline]
pub fn function(&self) -> &str { pub fn function(&self) -> &str {
self.function self.function
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |function| function) .map_or(Self::DEFAULT, |function| function)
} }
#[inline]
pub fn variable(&self) -> &str { pub fn variable(&self) -> &str {
self.variable self.variable
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |variable| variable) .map_or(Self::DEFAULT, |variable| variable)
} }
#[inline]
pub fn constant(&self) -> &str { pub fn constant(&self) -> &str {
self.constant self.constant
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |constant| constant) .map_or(Self::DEFAULT, |constant| constant)
} }
#[inline]
pub fn string(&self) -> &str { pub fn string(&self) -> &str {
self.string.as_ref().map_or(Self::DEFAULT, |string| string) self.string.as_ref().map_or(Self::DEFAULT, |string| string)
} }
#[inline]
pub fn number(&self) -> &str { pub fn number(&self) -> &str {
self.number.as_ref().map_or(Self::DEFAULT, |number| number) self.number.as_ref().map_or(Self::DEFAULT, |number| number)
} }
#[inline]
pub fn boolean(&self) -> &str { pub fn boolean(&self) -> &str {
self.boolean self.boolean
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |boolean| boolean) .map_or(Self::DEFAULT, |boolean| boolean)
} }
#[inline]
pub fn array(&self) -> &str { pub fn array(&self) -> &str {
self.array.as_ref().map_or(Self::DEFAULT, |array| array) self.array.as_ref().map_or(Self::DEFAULT, |array| array)
} }
#[inline]
pub fn object(&self) -> &str { pub fn object(&self) -> &str {
self.object.as_ref().map_or(Self::DEFAULT, |object| object) self.object.as_ref().map_or(Self::DEFAULT, |object| object)
} }
#[inline]
pub fn key(&self) -> &str { pub fn key(&self) -> &str {
self.key.as_ref().map_or(Self::DEFAULT, |key| key) self.key.as_ref().map_or(Self::DEFAULT, |key| key)
} }
#[inline]
pub fn null(&self) -> &str { pub fn null(&self) -> &str {
self.null.as_ref().map_or(Self::DEFAULT, |null| null) self.null.as_ref().map_or(Self::DEFAULT, |null| null)
} }
#[inline]
pub fn enum_member(&self) -> &str { pub fn enum_member(&self) -> &str {
self.enum_member self.enum_member
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |enum_member| enum_member) .map_or(Self::DEFAULT, |enum_member| enum_member)
} }
#[inline]
pub fn r#struct(&self) -> &str { pub fn r#struct(&self) -> &str {
self.r#struct self.r#struct
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |r#struct| r#struct) .map_or(Self::DEFAULT, |r#struct| r#struct)
} }
#[inline]
pub fn event(&self) -> &str { pub fn event(&self) -> &str {
self.event.as_ref().map_or(Self::DEFAULT, |event| event) self.event.as_ref().map_or(Self::DEFAULT, |event| event)
} }
#[inline]
pub fn operator(&self) -> &str { pub fn operator(&self) -> &str {
self.operator self.operator
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |operator| operator) .map_or(Self::DEFAULT, |operator| operator)
} }
#[inline]
pub fn type_parameter(&self) -> &str { pub fn type_parameter(&self) -> &str {
self.type_parameter self.type_parameter
.as_ref() .as_ref()
@ -178,17 +229,24 @@ pub struct Diagnostic {
impl Diagnostic { impl Diagnostic {
const DEFAULT: &'static str = ""; const DEFAULT: &'static str = "";
#[inline]
pub fn hint(&self) -> &str { pub fn hint(&self) -> &str {
self.hint.as_ref().map_or(Self::DEFAULT, |hint| hint) self.hint.as_ref().map_or(Self::DEFAULT, |hint| hint)
} }
#[inline]
pub fn info(&self) -> &str { pub fn info(&self) -> &str {
self.info.as_ref().map_or(Self::DEFAULT, |info| info) self.info.as_ref().map_or(Self::DEFAULT, |info| info)
} }
#[inline]
pub fn warning(&self) -> &str { pub fn warning(&self) -> &str {
self.warning self.warning
.as_ref() .as_ref()
.map_or(Self::DEFAULT, |warning| warning) .map_or(Self::DEFAULT, |warning| warning)
} }
#[inline]
pub fn error(&self) -> &str { pub fn error(&self) -> &str {
self.error.as_ref().map_or(Self::DEFAULT, |error| error) self.error.as_ref().map_or(Self::DEFAULT, |error| error)
} }
@ -202,6 +260,7 @@ pub struct Vcs {
impl Vcs { impl Vcs {
const DEFAULT: &'static str = ""; const DEFAULT: &'static str = "";
#[inline]
pub fn icon(&self) -> &str { pub fn icon(&self) -> &str {
self.icon self.icon
.as_ref() .as_ref()
@ -217,11 +276,13 @@ pub struct Mime {
} }
impl Mime { impl Mime {
#[inline]
pub fn directory(&self) -> &str { pub fn directory(&self) -> &str {
self.directory.as_ref().map_or("", |directory| directory) self.directory.as_ref().map_or("", |directory| directory)
} }
// Returns the symbol that matches the name, if any, otherwise returns the name back. // Returns the symbol that matches the name, if any, otherwise returns the name back.
#[inline]
pub fn get<'name, 'mime: 'name>(&'mime self, r#type: &'name str) -> &'name str { pub fn get<'name, 'mime: 'name>(&'mime self, r#type: &'name str) -> &'name str {
self.mime.get(r#type).map_or(r#type, |mime| mime) self.mime.get(r#type).map_or(r#type, |mime| mime)
} }
@ -237,12 +298,14 @@ impl Dap {
const DEFAULT_VERIFIED: &'static str = ""; const DEFAULT_VERIFIED: &'static str = "";
const DEFAULT_UNVERIFIED: &'static str = ""; const DEFAULT_UNVERIFIED: &'static str = "";
#[inline]
pub fn verified(&self) -> &str { pub fn verified(&self) -> &str {
self.verified self.verified
.as_ref() .as_ref()
.map_or(Self::DEFAULT_VERIFIED, |verified| verified) .map_or(Self::DEFAULT_VERIFIED, |verified| verified)
} }
#[inline]
pub fn unverified(&self) -> &str { pub fn unverified(&self) -> &str {
self.verified self.verified
.as_ref() .as_ref()