Skip to content

Commit

Permalink
Eliminate a token clone from advance_left
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 20, 2022
1 parent d81740e commit d981c5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_ast_pretty/src/pp.rs
Expand Up @@ -319,7 +319,7 @@ impl Printer {
let mut left_size = self.buf.first().unwrap().size;

while left_size >= 0 {
let left = self.buf.first().unwrap().token.clone();
let left = self.buf.pop_first().unwrap().token;

let len = match left {
Token::Break(b) => b.blank_space,
Expand All @@ -335,7 +335,6 @@ impl Printer {

self.left_total += len;

self.buf.advance_left();
if self.buf.is_empty() {
break;
}
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_ast_pretty/src/pp/ring.rs
Expand Up @@ -32,11 +32,6 @@ impl<T> RingBuffer<T> {
index
}

pub fn advance_left(&mut self) {
self.data.pop_front().unwrap();
self.offset += 1;
}

pub fn clear(&mut self) {
self.data.clear();
}
Expand All @@ -53,6 +48,12 @@ impl<T> RingBuffer<T> {
self.data.front_mut()
}

pub fn pop_first(&mut self) -> Option<T> {
let first = self.data.pop_front()?;
self.offset += 1;
Some(first)
}

pub fn last(&self) -> Option<&T> {
self.data.back()
}
Expand Down

0 comments on commit d981c5b

Please sign in to comment.