Skip to content

Commit

Permalink
Check start of line in scanners for minimal case
Browse files Browse the repository at this point in the history
  • Loading branch information
SSJohns committed Jun 21, 2018
1 parent f9b0f9d commit 6abd790
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/scanners.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*!
In many of these cases the AST will be scanned and then it
is found there is no match. In many of these cases the scan
turns up False. It can be see that in the very simplest cases,
usually by doing a char check at the very begginning of the
line, we can eliminate these checks without the same allocations
that are done otherwise and cause the program considerable
slowdown.
*/

use pest::Parser;
use std::str;
use twoway::find_bytes;
Expand All @@ -24,6 +35,9 @@ fn is_match(rule: Rule, line: &[u8]) -> bool {

#[inline(always)]
pub fn atx_heading_start(line: &[u8]) -> Option<usize> {
if line[0] != b'#'{
return None
}
search(Rule::atx_heading_start, line)
}

Expand Down Expand Up @@ -55,11 +69,17 @@ pub fn html_block_end_5(line: &[u8]) -> bool {

#[inline(always)]
pub fn open_code_fence(line: &[u8]) -> Option<usize> {
if line[0] != b'`' && line[0] != b'~' {
return None
}
search(Rule::open_code_fence, line)
}

#[inline(always)]
pub fn close_code_fence(line: &[u8]) -> Option<usize> {
if line[0] != b'`' && line[0] != b'~' {
return None
}
search(Rule::close_code_fence, line)
}

Expand Down Expand Up @@ -108,7 +128,8 @@ pub enum SetextChar {

#[inline(always)]
pub fn setext_heading_line(line: &[u8]) -> Option<SetextChar> {
if is_match(Rule::setext_heading_line, line) {
if (line[0] == b'=' || line[0] == b'-')
&& is_match(Rule::setext_heading_line, line) {
if line[0] == b'=' {
Some(SetextChar::Equals)
} else {
Expand All @@ -121,6 +142,9 @@ pub fn setext_heading_line(line: &[u8]) -> Option<SetextChar> {

#[inline(always)]
pub fn thematic_break(line: &[u8]) -> Option<usize> {
if line[0] != b'*' && line[0] != b'-' && line[0] != b'_' {
return None
}
search(Rule::thematic_break, line)
}

Expand Down

0 comments on commit 6abd790

Please sign in to comment.