Skip to content

Commit b1aae60

Browse files
committed
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.
1 parent 4465b2f commit b1aae60

File tree

1 file changed

+15
-16
lines changed
  • src/libsyntax/parse/lexer

1 file changed

+15
-16
lines changed

src/libsyntax/parse/lexer/mod.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -442,36 +442,35 @@ impl<'a> StringReader<'a> {
442442
/// Advance the StringReader by one character. If a newline is
443443
/// discovered, add it to the FileMap's list of line start offsets.
444444
pub fn bump(&mut self) {
445-
let new_pos = self.next_pos;
446-
let new_byte_offset = self.byte_offset(new_pos).to_usize();
445+
let next_byte_offset = self.byte_offset(self.next_pos).to_usize();
447446
let end = self.terminator.map_or(self.source_text.len(), |t| {
448447
self.byte_offset(t).to_usize()
449448
});
450-
if new_byte_offset < end {
451-
let old_ch_is_newline = self.ch.unwrap() == '\n';
452-
let new_ch = char_at(&self.source_text, new_byte_offset);
453-
let new_ch_len = new_ch.len_utf8();
454-
455-
self.ch = Some(new_ch);
456-
self.pos = new_pos;
457-
self.next_pos = new_pos + Pos::from_usize(new_ch_len);
458-
if old_ch_is_newline {
449+
if next_byte_offset < end {
450+
let next_ch = char_at(&self.source_text, next_byte_offset);
451+
let next_ch_len = next_ch.len_utf8();
452+
453+
if self.ch.unwrap() == '\n' {
459454
if self.save_new_lines_and_multibyte {
460-
self.filemap.next_line(self.pos);
455+
self.filemap.next_line(self.next_pos);
461456
}
462457
self.col = CharPos(0);
463458
} else {
464459
self.col = self.col + CharPos(1);
465460
}
466-
if new_ch_len > 1 {
461+
if next_ch_len > 1 {
467462
if self.save_new_lines_and_multibyte {
468-
self.filemap.record_multibyte_char(self.pos, new_ch_len);
463+
self.filemap.record_multibyte_char(self.next_pos, next_ch_len);
469464
}
470465
}
471-
self.filemap.record_width(self.pos, new_ch);
466+
self.filemap.record_width(self.next_pos, next_ch);
467+
468+
self.ch = Some(next_ch);
469+
self.pos = self.next_pos;
470+
self.next_pos = self.next_pos + Pos::from_usize(next_ch_len);
472471
} else {
473472
self.ch = None;
474-
self.pos = new_pos;
473+
self.pos = self.next_pos;
475474
}
476475
}
477476

0 commit comments

Comments
 (0)