Simplify search for bare \r in doc comments

Outer `if` is the fast path -- it calls into hyperoptimized memchr.

The inner loop is just the simplest code possible -- it doesn't
generated the tightest code, but that shouldn't matter if we are going
to error anyhow.
This commit is contained in:
Aleksey Kladov 2020-08-17 21:52:49 +02:00
parent 39197e673e
commit ccbe94bf77

View File

@ -323,20 +323,17 @@ impl<'a> StringReader<'a> {
comment_kind: CommentKind, comment_kind: CommentKind,
doc_style: DocStyle, doc_style: DocStyle,
) -> TokenKind { ) -> TokenKind {
let mut idx = 0; if content.contains('\r') {
loop { for (idx, _) in content.char_indices().filter(|&(_, c)| c == '\r') {
idx = match content[idx..].find('\r') { self.err_span_(
None => break, content_start + BytePos(idx as u32),
Some(it) => idx + it + 1, content_start + BytePos(idx as u32 + 1),
}; match comment_kind {
self.err_span_( CommentKind::Line => "bare CR not allowed in doc-comment",
content_start + BytePos(idx as u32 - 1), CommentKind::Block => "bare CR not allowed in block doc-comment",
content_start + BytePos(idx as u32), },
match comment_kind { );
CommentKind::Line => "bare CR not allowed in doc-comment", }
CommentKind::Block => "bare CR not allowed in block doc-comment",
},
);
} }
let attr_style = match doc_style { let attr_style = match doc_style {