Add inlining for some charstate functions

pull/1/head
trivernis 5 years ago
parent a320363764
commit 86ff2e17d1

2
Cargo.lock generated

@ -566,7 +566,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "snekdown" name = "snekdown"
version = "0.12.1" version = "0.12.2"
dependencies = [ dependencies = [
"chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)",

@ -1,6 +1,6 @@
[package] [package]
name = "snekdown" name = "snekdown"
version = "0.12.1" version = "0.12.2"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" edition = "2018"
license-file = "LICENSE" license-file = "LICENSE"

@ -54,6 +54,7 @@ pub trait CharStateMachine {
impl CharStateMachine for Parser { impl CharStateMachine for Parser {
/// Increments the current index and returns the /// Increments the current index and returns the
/// char at the indexes position /// char at the indexes position
#[inline]
fn next_char(&mut self) -> Option<char> { fn next_char(&mut self) -> Option<char> {
self.index += 1; self.index += 1;
self.previous_char = self.current_char; self.previous_char = self.current_char;
@ -63,11 +64,13 @@ impl CharStateMachine for Parser {
} }
/// skips to the next char /// skips to the next char
#[inline]
fn skip_char(&mut self) { fn skip_char(&mut self) {
let _ = self.next_char(); let _ = self.next_char();
} }
/// Returns to an index position /// Returns to an index position
#[inline]
fn revert_to(&mut self, index: usize) -> Result<(), ParseError> { fn revert_to(&mut self, index: usize) -> Result<(), ParseError> {
if let Some(char) = self.text.get(index) { if let Some(char) = self.text.get(index) {
self.index = index; self.index = index;
@ -84,6 +87,7 @@ impl CharStateMachine for Parser {
} }
/// reverts and returns a parse error /// reverts and returns a parse error
#[inline]
fn revert_with_error(&mut self, index: usize) -> ParseError { fn revert_with_error(&mut self, index: usize) -> ParseError {
let err = ParseError::new(self.index); let err = ParseError::new(self.index);
@ -141,6 +145,7 @@ impl CharStateMachine for Parser {
} }
/// checks if the input character is escaped /// checks if the input character is escaped
#[inline]
fn check_escaped(&self) -> bool { fn check_escaped(&self) -> bool {
if self.index == 0 { if self.index == 0 {
return false; return false;
@ -152,6 +157,7 @@ impl CharStateMachine for Parser {
} }
/// checks if the current character is the given input character and not escaped /// checks if the current character is the given input character and not escaped
#[inline]
fn check_special(&self, character: &char) -> bool { fn check_special(&self, character: &char) -> bool {
self.current_char == *character && !self.check_escaped() self.current_char == *character && !self.check_escaped()
} }
@ -198,10 +204,12 @@ impl CharStateMachine for Parser {
/// returns if the current character is a linebreak character /// returns if the current character is a linebreak character
/// Note: No one likes CRLF /// Note: No one likes CRLF
#[inline]
fn check_linebreak(&self) -> bool { fn check_linebreak(&self) -> bool {
self.current_char == LB && !self.check_escaped() self.current_char == LB && !self.check_escaped()
} }
#[inline]
fn assert_special(&mut self, character: &char, revert_index: usize) -> Result<(), ParseError> { fn assert_special(&mut self, character: &char, revert_index: usize) -> Result<(), ParseError> {
if self.check_special(character) { if self.check_special(character) {
Ok(()) Ok(())
@ -210,6 +218,7 @@ impl CharStateMachine for Parser {
} }
} }
#[inline]
fn assert_special_group( fn assert_special_group(
&mut self, &mut self,
group: &[char], group: &[char],

Loading…
Cancel
Save