Merge pull request #346 from epage/inline

perf: Remove some function overhead
This commit is contained in:
Ed Page 2021-09-15 08:17:47 -05:00 committed by GitHub
commit ff3d2fd00a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -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<Item = &mut Cow<'c, str>> {
match self {
Status::Corrections(corrections) => itertools::Either::Left(corrections.iter_mut()),

View file

@ -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<Item = Word<'t>> {
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
}