mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
direct indexing into the slice
This commit is contained in:
parent
8f97c217a5
commit
c6b13984ed
1 changed files with 8 additions and 11 deletions
|
@ -279,6 +279,7 @@ fn eat_line_comment<'a>(
|
||||||
|
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
let bytes = state.bytes();
|
let bytes = state.bytes();
|
||||||
|
let length = bytes.len();
|
||||||
|
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
let is_doc_comment = if let Some(b'#') = bytes.get(index) {
|
let is_doc_comment = if let Some(b'#') = bytes.get(index) {
|
||||||
|
@ -351,15 +352,12 @@ fn eat_line_comment<'a>(
|
||||||
|
|
||||||
let loop_start = index;
|
let loop_start = index;
|
||||||
|
|
||||||
let initial = state.bytes();
|
while index < length {
|
||||||
let mut it = initial.iter();
|
match bytes[index] {
|
||||||
|
|
||||||
while let Some(c) = it.next() {
|
|
||||||
match c {
|
|
||||||
b'\t' => return HasTab(state),
|
b'\t' => return HasTab(state),
|
||||||
b'\n' => {
|
b'\n' => {
|
||||||
let delta = initial.len() - state.bytes().len();
|
let comment =
|
||||||
let comment = unsafe { std::str::from_utf8_unchecked(&initial[..delta]) };
|
unsafe { std::str::from_utf8_unchecked(&bytes[loop_start..index]) };
|
||||||
|
|
||||||
if is_doc_comment {
|
if is_doc_comment {
|
||||||
comments_and_newlines.push(CommentOrNewline::DocComment(comment));
|
comments_and_newlines.push(CommentOrNewline::DocComment(comment));
|
||||||
|
@ -370,8 +368,8 @@ fn eat_line_comment<'a>(
|
||||||
multiline = true;
|
multiline = true;
|
||||||
|
|
||||||
index += 1;
|
index += 1;
|
||||||
while let Some(c) = it.next() {
|
while index < length {
|
||||||
match c {
|
match bytes[index] {
|
||||||
b' ' => {
|
b' ' => {
|
||||||
state = state.advance(1);
|
state = state.advance(1);
|
||||||
}
|
}
|
||||||
|
@ -415,8 +413,7 @@ fn eat_line_comment<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// We made it to the end of the bytes. This means there's a comment without a trailing newline.
|
// We made it to the end of the bytes. This means there's a comment without a trailing newline.
|
||||||
let delta = initial.len() - state.bytes().len();
|
let comment = unsafe { std::str::from_utf8_unchecked(&bytes[loop_start..index]) };
|
||||||
let comment = unsafe { std::str::from_utf8_unchecked(&bytes[loop_start..delta]) };
|
|
||||||
|
|
||||||
if is_doc_comment {
|
if is_doc_comment {
|
||||||
comments_and_newlines.push(CommentOrNewline::DocComment(comment));
|
comments_and_newlines.push(CommentOrNewline::DocComment(comment));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue