diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2018-05-04 06:38:15 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2018-05-13 17:16:02 +1000 |
| commit | b1aae607c56d26333589dc45daa20859950bf6e1 (patch) | |
| tree | 5176bd1545845ef82e9d27fb88be013789e3514d /src/libsyntax/parse | |
| parent | 4465b2fbf3487e8f45e2eee4da187776574febec (diff) | |
| download | rust-b1aae607c56d26333589dc45daa20859950bf6e1.tar.gz rust-b1aae607c56d26333589dc45daa20859950bf6e1.zip | |
Tweak naming and ordering in `StringReader::bump()`.
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.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 22a0261d8c6..a24af857af1 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -442,36 +442,35 @@ impl<'a> StringReader<'a> { /// 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; } } |
