Skip to content

Commit 2e00ec7

Browse files
author
SSJohns
committed
Check start of line in scanners for minimal case
1 parent f9b0f9d commit 2e00ec7

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/scanners.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/*!
2+
In many of these cases the AST will be scanned and then it
3+
is found there is no match. In many of these cases the scan
4+
turns up False. It can be see that in the very simplest cases,
5+
usually by doing a char check at the very begginning of the
6+
line, we can eliminate these checks without the same allocations
7+
that are done otherwise and cause the program considerable
8+
slowdown.
9+
10+
*/
11+
112
use pest::Parser;
213
use std::str;
314
use twoway::find_bytes;
@@ -23,8 +34,17 @@ fn is_match(rule: Rule, line: &[u8]) -> bool {
2334
}
2435

2536
#[inline(always)]
37+
<<<<<<< HEAD
2638
pub fn atx_heading_start(line: &[u8]) -> Option<usize> {
2739
search(Rule::atx_heading_start, line)
40+
=======
41+
pub fn atx_heading_start(line: &[u8], reddit_quirks: bool) -> Option<usize> {
42+
match (reddit_quirks, line[0] == b'#') {
43+
(true, true) => search(Rule::atx_heading_start_reddit, line),
44+
(false, true) => search(Rule::atx_heading_start, line),
45+
_ => None,
46+
}
47+
>>>>>>> 610495c... Check start of line in scanners for minimal case
2848
}
2949

3050
#[inline(always)]
@@ -55,11 +75,17 @@ pub fn html_block_end_5(line: &[u8]) -> bool {
5575

5676
#[inline(always)]
5777
pub fn open_code_fence(line: &[u8]) -> Option<usize> {
78+
if line[0] != b'`' && line[0] != b'~' {
79+
return None
80+
}
5881
search(Rule::open_code_fence, line)
5982
}
6083

6184
#[inline(always)]
6285
pub fn close_code_fence(line: &[u8]) -> Option<usize> {
86+
if line[0] != b'`' && line[0] != b'~' {
87+
return None
88+
}
6389
search(Rule::close_code_fence, line)
6490
}
6591

@@ -108,7 +134,8 @@ pub enum SetextChar {
108134

109135
#[inline(always)]
110136
pub fn setext_heading_line(line: &[u8]) -> Option<SetextChar> {
111-
if is_match(Rule::setext_heading_line, line) {
137+
if (line[0] == b'=' || line[0] == b'-')
138+
&& is_match(Rule::setext_heading_line, line) {
112139
if line[0] == b'=' {
113140
Some(SetextChar::Equals)
114141
} else {
@@ -121,6 +148,9 @@ pub fn setext_heading_line(line: &[u8]) -> Option<SetextChar> {
121148

122149
#[inline(always)]
123150
pub fn thematic_break(line: &[u8]) -> Option<usize> {
151+
if line[0] != b'*' && line[0] != b'-' && line[0] != b'_' {
152+
return None
153+
}
124154
search(Rule::thematic_break, line)
125155
}
126156

0 commit comments

Comments
 (0)