From efae838e5c8d40b82ca8d9c3b66e46ab76d90286 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 14 Sep 2021 21:09:24 -0500 Subject: [PATCH] perf: Remove some function overhead Unfortunately, almost all of this is for corrections. --- crates/typos/src/dict.rs | 4 ++++ crates/typos/src/tokens.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/crates/typos/src/dict.rs b/crates/typos/src/dict.rs index a5bc5e6..deed6d9 100644 --- a/crates/typos/src/dict.rs +++ b/crates/typos/src/dict.rs @@ -24,16 +24,20 @@ pub enum Status<'c> { } impl<'c> Status<'c> { + #[inline] pub fn is_invalid(&self) -> bool { matches!(self, Status::Invalid) } + #[inline] pub fn is_valid(&self) -> bool { matches!(self, Status::Valid) } + #[inline] pub fn is_correction(&self) -> bool { matches!(self, Status::Corrections(_)) } + #[inline] pub fn corrections_mut(&mut self) -> impl Iterator> { match self { Status::Corrections(corrections) => itertools::Either::Left(corrections.iter_mut()), diff --git a/crates/typos/src/tokens.rs b/crates/typos/src/tokens.rs index 7c1ce31..992f1e6 100644 --- a/crates/typos/src/tokens.rs +++ b/crates/typos/src/tokens.rs @@ -7,16 +7,19 @@ pub struct TokenizerBuilder { } impl TokenizerBuilder { + #[inline] pub fn new() -> Self { Default::default() } /// Specify that unicode Identifiers are allowed. + #[inline] pub fn unicode(&mut self, yes: bool) -> &mut Self { self.unicode = yes; self } + #[inline] pub fn build(&self) -> Tokenizer { let TokenizerBuilder { unicode } = self.clone(); Tokenizer { unicode } @@ -36,6 +39,7 @@ pub struct Tokenizer { } impl Tokenizer { + #[inline] pub fn new() -> Self { TokenizerBuilder::default().build() } @@ -595,6 +599,7 @@ pub struct Identifier<'t> { } impl<'t> Identifier<'t> { + #[inline] pub fn new_unchecked(token: &'t str, case: Case, offset: usize) -> Self { Self { token, @@ -603,19 +608,23 @@ impl<'t> Identifier<'t> { } } + #[inline] pub fn token(&self) -> &'t str { self.token } + #[inline] pub fn case(&self) -> Case { self.case } + #[inline] pub fn offset(&self) -> usize { self.offset } /// Split into individual Words. + #[inline] pub fn split(&self) -> impl Iterator> { match self.case { Case::None => itertools::Either::Left(SplitIdent::new(self.token, self.offset)), @@ -659,6 +668,7 @@ impl<'t> Word<'t> { Ok(item) } + #[inline] pub fn new_unchecked(token: &'t str, case: Case, offset: usize) -> Self { Self { token, @@ -667,14 +677,17 @@ impl<'t> Word<'t> { } } + #[inline] pub fn token(&self) -> &'t str { self.token } + #[inline] pub fn case(&self) -> Case { self.case } + #[inline] pub fn offset(&self) -> usize { self.offset }