Add inlining for some charstate functions

pull/1/head
trivernis 4 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]]
name = "snekdown"
version = "0.12.1"
version = "0.12.2"
dependencies = [
"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)",

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

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

Loading…
Cancel
Save