mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-23 08:02:15 -05:00
Merge pull request #346 from epage/inline
perf: Remove some function overhead
This commit is contained in:
commit
ff3d2fd00a
2 changed files with 17 additions and 0 deletions
|
@ -24,16 +24,20 @@ pub enum Status<'c> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'c> Status<'c> {
|
impl<'c> Status<'c> {
|
||||||
|
#[inline]
|
||||||
pub fn is_invalid(&self) -> bool {
|
pub fn is_invalid(&self) -> bool {
|
||||||
matches!(self, Status::Invalid)
|
matches!(self, Status::Invalid)
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
pub fn is_valid(&self) -> bool {
|
pub fn is_valid(&self) -> bool {
|
||||||
matches!(self, Status::Valid)
|
matches!(self, Status::Valid)
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
pub fn is_correction(&self) -> bool {
|
pub fn is_correction(&self) -> bool {
|
||||||
matches!(self, Status::Corrections(_))
|
matches!(self, Status::Corrections(_))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn corrections_mut(&mut self) -> impl Iterator<Item = &mut Cow<'c, str>> {
|
pub fn corrections_mut(&mut self) -> impl Iterator<Item = &mut Cow<'c, str>> {
|
||||||
match self {
|
match self {
|
||||||
Status::Corrections(corrections) => itertools::Either::Left(corrections.iter_mut()),
|
Status::Corrections(corrections) => itertools::Either::Left(corrections.iter_mut()),
|
||||||
|
|
|
@ -7,16 +7,19 @@ pub struct TokenizerBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TokenizerBuilder {
|
impl TokenizerBuilder {
|
||||||
|
#[inline]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Specify that unicode Identifiers are allowed.
|
/// Specify that unicode Identifiers are allowed.
|
||||||
|
#[inline]
|
||||||
pub fn unicode(&mut self, yes: bool) -> &mut Self {
|
pub fn unicode(&mut self, yes: bool) -> &mut Self {
|
||||||
self.unicode = yes;
|
self.unicode = yes;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn build(&self) -> Tokenizer {
|
pub fn build(&self) -> Tokenizer {
|
||||||
let TokenizerBuilder { unicode } = self.clone();
|
let TokenizerBuilder { unicode } = self.clone();
|
||||||
Tokenizer { unicode }
|
Tokenizer { unicode }
|
||||||
|
@ -36,6 +39,7 @@ pub struct Tokenizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tokenizer {
|
impl Tokenizer {
|
||||||
|
#[inline]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
TokenizerBuilder::default().build()
|
TokenizerBuilder::default().build()
|
||||||
}
|
}
|
||||||
|
@ -595,6 +599,7 @@ pub struct Identifier<'t> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'t> Identifier<'t> {
|
impl<'t> Identifier<'t> {
|
||||||
|
#[inline]
|
||||||
pub fn new_unchecked(token: &'t str, case: Case, offset: usize) -> Self {
|
pub fn new_unchecked(token: &'t str, case: Case, offset: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
token,
|
token,
|
||||||
|
@ -603,19 +608,23 @@ impl<'t> Identifier<'t> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn token(&self) -> &'t str {
|
pub fn token(&self) -> &'t str {
|
||||||
self.token
|
self.token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn case(&self) -> Case {
|
pub fn case(&self) -> Case {
|
||||||
self.case
|
self.case
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn offset(&self) -> usize {
|
pub fn offset(&self) -> usize {
|
||||||
self.offset
|
self.offset
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Split into individual Words.
|
/// Split into individual Words.
|
||||||
|
#[inline]
|
||||||
pub fn split(&self) -> impl Iterator<Item = Word<'t>> {
|
pub fn split(&self) -> impl Iterator<Item = Word<'t>> {
|
||||||
match self.case {
|
match self.case {
|
||||||
Case::None => itertools::Either::Left(SplitIdent::new(self.token, self.offset)),
|
Case::None => itertools::Either::Left(SplitIdent::new(self.token, self.offset)),
|
||||||
|
@ -659,6 +668,7 @@ impl<'t> Word<'t> {
|
||||||
Ok(item)
|
Ok(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn new_unchecked(token: &'t str, case: Case, offset: usize) -> Self {
|
pub fn new_unchecked(token: &'t str, case: Case, offset: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
token,
|
token,
|
||||||
|
@ -667,14 +677,17 @@ impl<'t> Word<'t> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn token(&self) -> &'t str {
|
pub fn token(&self) -> &'t str {
|
||||||
self.token
|
self.token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn case(&self) -> Case {
|
pub fn case(&self) -> Case {
|
||||||
self.case
|
self.case
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn offset(&self) -> usize {
|
pub fn offset(&self) -> usize {
|
||||||
self.offset
|
self.offset
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue