Skip to content

Commit

Permalink
perf(parse): Further speed up array whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 29, 2024
1 parent ee902db commit 2ac134f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 10 additions & 6 deletions crates/toml_edit/src/parser/trivia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use winnow::combinator::empty;
use winnow::combinator::eof;
use winnow::combinator::fail;
use winnow::combinator::opt;
use winnow::combinator::peek;
use winnow::combinator::repeat;
use winnow::combinator::terminated;
use winnow::prelude::*;
Expand Down Expand Up @@ -90,12 +91,15 @@ pub(crate) fn ws_newlines<'i>(input: &mut Input<'i>) -> PResult<()> {
// note: this rule is not present in the original grammar
// ws-comment-newline = *( ws-newline-nonempty / comment )
pub(crate) fn ws_comment_newline<'i>(input: &mut Input<'i>) -> PResult<()> {

Check failure

Code scanning / clippy

the following explicit lifetimes could be elided: 'i Error

the following explicit lifetimes could be elided: 'i

Check failure

Code scanning / clippy

the following explicit lifetimes could be elided: 'i Error

the following explicit lifetimes could be elided: 'i

Check failure

Code scanning / clippy

the following explicit lifetimes could be elided: 'i Error

the following explicit lifetimes could be elided: 'i

Check failure

Code scanning / clippy

the following explicit lifetimes could be elided: 'i Error

the following explicit lifetimes could be elided: 'i
(
repeat(0.., (take_while(0.., WSCHAR), opt(comment), newline)).map(|()| ()),
take_while(0.., WSCHAR),
)
.void()
.parse_next(input)
let _ = ws.parse_next(input)?;

dispatch! {opt(peek(any));
Some(b'#') => (comment, newline, ws_comment_newline).void(),
Some(b'\n') => (newline, ws_comment_newline).void(),
Some(b'\r') => (newline, ws_comment_newline).void(),
_ => empty,
}
.parse_next(input)
}

// note: this rule is not present in the original grammar
Expand Down
7 changes: 3 additions & 4 deletions crates/toml_edit/tests/testsuite/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,12 @@ TOML parse error at line 1, column 1
bad!(
"a = [ \r ]",
str![[r#"
TOML parse error at line 1, column 7
TOML parse error at line 1, column 8
|
1 | a = [
]
| ^
invalid array
expected `]`
| ^
"#]]
);
Expand Down

0 comments on commit 2ac134f

Please sign in to comment.