]> git.lizzy.rs Git - rust.git/commitdiff
Tweak naming and ordering in `StringReader::bump()`.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 3 May 2018 20:38:15 +0000 (06:38 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Sun, 13 May 2018 07:16:02 +0000 (17:16 +1000)
This patch removes the "old"/"new" names in favour of "foo"/"next_foo",
which matches the field names.

It also moves the setting of `self.{ch,pos,next_pos}` in the common case
to the end, so that the meaning of "foo"/"next_foo" is consistent until
the end.

src/libsyntax/parse/lexer/mod.rs

index 22a0261d8c6b15fe9c05b4ce9e2634aa6f69d9b4..a24af857af1425c593bad3f0d5ef1674c98b0d38 100644 (file)
@@ -442,36 +442,35 @@ fn translate_crlf_(rdr: &StringReader,
     /// Advance the StringReader by one character. If a newline is
     /// discovered, add it to the FileMap's list of line start offsets.
     pub fn bump(&mut self) {
-        let new_pos = self.next_pos;
-        let new_byte_offset = self.byte_offset(new_pos).to_usize();
+        let next_byte_offset = self.byte_offset(self.next_pos).to_usize();
         let end = self.terminator.map_or(self.source_text.len(), |t| {
             self.byte_offset(t).to_usize()
         });
-        if new_byte_offset < end {
-            let old_ch_is_newline = self.ch.unwrap() == '\n';
-            let new_ch = char_at(&self.source_text, new_byte_offset);
-            let new_ch_len = new_ch.len_utf8();
-
-            self.ch = Some(new_ch);
-            self.pos = new_pos;
-            self.next_pos = new_pos + Pos::from_usize(new_ch_len);
-            if old_ch_is_newline {
+        if next_byte_offset < end {
+            let next_ch = char_at(&self.source_text, next_byte_offset);
+            let next_ch_len = next_ch.len_utf8();
+
+            if self.ch.unwrap() == '\n' {
                 if self.save_new_lines_and_multibyte {
-                    self.filemap.next_line(self.pos);
+                    self.filemap.next_line(self.next_pos);
                 }
                 self.col = CharPos(0);
             } else {
                 self.col = self.col + CharPos(1);
             }
-            if new_ch_len > 1 {
+            if next_ch_len > 1 {
                 if self.save_new_lines_and_multibyte {
-                    self.filemap.record_multibyte_char(self.pos, new_ch_len);
+                    self.filemap.record_multibyte_char(self.next_pos, next_ch_len);
                 }
             }
-            self.filemap.record_width(self.pos, new_ch);
+            self.filemap.record_width(self.next_pos, next_ch);
+
+            self.ch = Some(next_ch);
+            self.pos = self.next_pos;
+            self.next_pos = self.next_pos + Pos::from_usize(next_ch_len);
         } else {
             self.ch = None;
-            self.pos = new_pos;
+            self.pos = self.next_pos;
         }
     }