diff options
| author | bors <bors@rust-lang.org> | 2018-05-18 00:09:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-05-18 00:09:37 +0000 |
| commit | bedbf727855d099963b66cf6619a53d3c073f52a (patch) | |
| tree | 88291d1dd341f375121d266d896c94af0f570b2f /src/libsyntax/parse/lexer/comments.rs | |
| parent | 612ca14b817a2088ab0b6a697279d9e2aff1fb25 (diff) | |
| parent | e913d692117e57ea2908461865aa08037f0bd2b9 (diff) | |
| download | rust-bedbf727855d099963b66cf6619a53d3c073f52a.tar.gz rust-bedbf727855d099963b66cf6619a53d3c073f52a.zip | |
Auto merge of #50566 - nnethercote:bump, r=petrochenkov
Streamline `StringReader::bump` These patches make `bump` smaller and nicer. They speed up most runs for coercions and tuple-stress by 1--3%.
Diffstat (limited to 'src/libsyntax/parse/lexer/comments.rs')
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 63aa5d28ce8..672b0b9bbd1 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -238,7 +238,19 @@ fn read_block_comment(rdr: &mut StringReader, debug!(">>> block comment"); let p = rdr.pos; let mut lines: Vec<String> = Vec::new(); - let col = rdr.col; + + // Count the number of chars since the start of the line by rescanning. + let mut src_index = rdr.src_index(rdr.filemap.line_begin_pos()); + let end_src_index = rdr.src_index(rdr.pos); + assert!(src_index <= end_src_index); + let mut n = 0; + while src_index < end_src_index { + let c = char_at(&rdr.src, src_index); + src_index += c.len_utf8(); + n += 1; + } + let col = CharPos(n); + rdr.bump(); rdr.bump(); |
