Skip to content

Commit

Permalink
Improve rust-style identifiers code
Browse files Browse the repository at this point in the history
There is no reason to heap allocate for each individual character (or each group of characters?) when the allocated collection isn't even going to be used anyway
  • Loading branch information
LoganDark authored and Geal committed Mar 14, 2022
1 parent 6892982 commit 481cd2d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc/nom_recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ letters and numbers may be parsed like this:
use nom::{
IResult,
branch::alt,
multi::many0,
multi::many0_count,
combinator::recognize,
sequence::pair,
character::complete::{alpha1, alphanumeric1},
Expand All @@ -126,7 +126,7 @@ pub fn identifier(input: &str) -> IResult<&str, &str> {
recognize(
pair(
alt((alpha1, tag("_"))),
many0(alt((alphanumeric1, tag("_"))))
many0_count(alt((alphanumeric1, tag("_"))))
)
)(input)
}
Expand Down

0 comments on commit 481cd2d

Please sign in to comment.