Skip to content

Commit

Permalink
Reuse scanning for $ or \ in arg macro parser
Browse files Browse the repository at this point in the history
Reviewed By: ezgicicek

Differential Revision: D58430978

fbshipit-source-id: 38961a716ba5fef6196081d70a680c65c309d036
  • Loading branch information
stepancheg authored and facebook-github-bot committed Jun 19, 2024
1 parent 4942595 commit ea0165d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/buck2_node/src/attrs/attr_type/arg/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ fn read_literal_opt(input: &str) -> Result<Option<Box<str>>> {

// Fast check that there are no macro refs in the string, which is the common case.
// We can do better than `memchr` (given our strings are short), but not much.
if memchr::memchr2(b'$', b'\\', input.as_bytes()).is_none() {
return Ok((Some(input.into()), ""));
match memchr::memchr2(b'$', b'\\', input.as_bytes()) {
None => Ok((Some(input.into()), "")),
Some(pos) => read_literal_opt_slow(input, pos),
}

read_literal_opt_slow(input)
}

fn read_literal_opt_slow(input: &str) -> Result<Option<Box<str>>> {
let mut char_indices = input.bytes().enumerate();
fn read_literal_opt_slow(input: &str, pos: usize) -> Result<Option<Box<str>>> {
let mut char_indices = input.bytes().enumerate().skip(pos);

let mut indices_to_drop = Vec::new();
enum State {
Searching,
Expand Down

0 comments on commit ea0165d

Please sign in to comment.