Skip to content

Commit

Permalink
perf(parse): Speed up newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 29, 2024
1 parent 4e9b4e8 commit ee902db
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/toml_edit/src/parser/trivia.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::ops::RangeInclusive;

use winnow::combinator::alt;
use winnow::combinator::empty;
use winnow::combinator::eof;
use winnow::combinator::fail;
use winnow::combinator::opt;
use winnow::combinator::repeat;
use winnow::combinator::terminated;
use winnow::prelude::*;
use winnow::token::any;
use winnow::token::one_of;
use winnow::token::take_while;

Expand Down Expand Up @@ -59,7 +62,12 @@ pub(crate) fn comment<'i>(input: &mut Input<'i>) -> PResult<()> {
// newline = ( %x0A / ; LF
// %x0D.0A ) ; CRLF
pub(crate) fn newline(input: &mut Input<'_>) -> PResult<()> {
alt((one_of(LF).void(), (one_of(CR), one_of(LF)).void())).parse_next(input)
dispatch! {any;
b'\n' => empty,
b'\r' => one_of(LF).void(),
_ => fail,
}
.parse_next(input)
}
pub(crate) const LF: u8 = b'\n';
pub(crate) const CR: u8 = b'\r';
Expand Down

0 comments on commit ee902db

Please sign in to comment.