diff --git a/Cargo.toml b/Cargo.toml index 5a1b51a..92af11b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/parser.rs b/src/parser.rs index e92dce0..adcf0f4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 { - 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,