From 49960ad2503eb050e02c6c428111a59d5bc16ba3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 3 Oct 2016 18:57:18 +1100 Subject: [PATCH 1/2] Streamline StringReader::bump. First, assert! is redundant w.r.t. the unwrap() immediately afterwards. Second, `byte_offset_diff` is effectively computed as `current_byte_offset + ch.len_utf8() - current_byte_offset` (with `next` as an intermediate) which is silly and can be simplified. --- src/libsyntax/parse/lexer/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 6c0e2425d37ad..1b326aeb8ea95 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -417,11 +417,9 @@ impl<'a> StringReader<'a> { self.last_pos = self.pos; let current_byte_offset = self.byte_offset(self.pos).to_usize(); if current_byte_offset < self.source_text.len() { - assert!(self.curr.is_some()); let last_char = self.curr.unwrap(); let ch = char_at(&self.source_text, current_byte_offset); - let next = current_byte_offset + ch.len_utf8(); - let byte_offset_diff = next - current_byte_offset; + let byte_offset_diff = ch.len_utf8(); self.pos = self.pos + Pos::from_usize(byte_offset_diff); self.curr = Some(ch); self.col = self.col + CharPos(1); From 9e3dcb45493366c790d333aaf4dfa5a043e49a63 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 3 Oct 2016 18:58:35 +1100 Subject: [PATCH 2/2] Simplify `start_bpos` calculation in scan_comment(). The two branches of this `if` compute the same value. This commit gets rid of the first branch, which makes this calculation identical to the one in scan_block_comment(). --- src/libsyntax/parse/lexer/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 1b326aeb8ea95..0ba2db3310cda 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -507,11 +507,7 @@ impl<'a> StringReader<'a> { // line comments starting with "///" or "//!" are doc-comments let doc_comment = self.curr_is('/') || self.curr_is('!'); - let start_bpos = if doc_comment { - self.pos - BytePos(3) - } else { - self.last_pos - BytePos(2) - }; + let start_bpos = self.last_pos - BytePos(2); while !self.is_eof() { match self.curr.unwrap() {