Created
August 12, 2017 07:31
-
-
Save jsimmons/22d7ebad59dbc63af9e3f34387eaff4f to your computer and use it in GitHub Desktop.
Whitespace skipper approach one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[inline(force)] | |
let cur = |data: &[u8], pos| -> usize { | |
unsafe { *data.get_unchecked(pos) as usize } | |
}; | |
#[inline(force)] | |
let skip_whitespace = |data, pos| -> usize { | |
let mut ws = 0; | |
'outer: while PARSE_FLAGS[cur(data, pos + ws)] & PARSE_FLAG_WS != 0 { | |
'skip_ws: loop { | |
if flags(cur(data, pos + ws + 1)) & PARSE_FLAG_WS == 0 { ws = ws + 1; break 'skip_ws; } | |
if flags(cur(data, pos + ws + 2)) & PARSE_FLAG_WS == 0 { ws = ws + 2; break 'skip_ws; } | |
if flags(cur(data, pos + ws + 3)) & PARSE_FLAG_WS == 0 { ws = ws + 3; break 'skip_ws; } | |
ws = ws + 4; | |
if flags(cur(data, pos + ws)) & PARSE_FLAG_WS == 0 { break 'skip_ws; } | |
} | |
if cur(data, pos + ws) != '#' as usize { | |
break 'outer; | |
} | |
ws = ws + 1; | |
'skip_comment: loop { | |
let c = cur(data, pos + ws); | |
if c == 0 || c == '\n' as usize || c == '\r' as usize { break 'skip_comment; } | |
ws = ws + 1; | |
} | |
} | |
pos + ws | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment