use memrchr

master
Edward Shen 2021-03-01 16:01:47 -05:00
parent c975a2ec14
commit cd2f58c920
Signed by: edward
GPG Key ID: 19182661E818369F
2 changed files with 2 additions and 11 deletions

View File

@ -16,6 +16,7 @@ exclude = ["fuzz/**/*", ".vscode/**/*"]
serde = ["serde_crate"]
[dependencies]
memchr = "2"
nom = { version = "6", default_features = false, features = ["std"] }
serde_crate = { version = "1", package = "serde", optional = true }

View File

@ -700,7 +700,7 @@ fn section_header(i: &[u8]) -> IResult<&[u8], ParsedSectionHeader> {
if let Ok((i, _)) = char::<_, NomError<&[u8]>>(']')(i) {
// Either section does not have a subsection or using deprecated
// subsection syntax at this point.
let header = match find_legacy_subsection_separator(name) {
let header = match memchr::memrchr(b'.', name.as_bytes()) {
Some(index) => ParsedSectionHeader {
name: Cow::Borrowed(&name[..index]),
separator: name.get(index..=index).map(|slice| Cow::Borrowed(slice)),
@ -747,16 +747,6 @@ fn section_header(i: &[u8]) -> IResult<&[u8], ParsedSectionHeader> {
))
}
fn find_legacy_subsection_separator(input: &str) -> Option<usize> {
let input = input.as_bytes();
for i in (0..input.len()).into_iter().rev() {
if input[i] == b'.' {
return Some(i);
}
}
None
}
fn section_body<'a, 'b, 'c>(
i: &'a [u8],
node: &'b mut ParserNode,