Skip to content

Commit d981c5b

Browse files
committed
Eliminate a token clone from advance_left
1 parent d81740e commit d981c5b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

compiler/rustc_ast_pretty/src/pp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl Printer {
319319
let mut left_size = self.buf.first().unwrap().size;
320320

321321
while left_size >= 0 {
322-
let left = self.buf.first().unwrap().token.clone();
322+
let left = self.buf.pop_first().unwrap().token;
323323

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

336336
self.left_total += len;
337337

338-
self.buf.advance_left();
339338
if self.buf.is_empty() {
340339
break;
341340
}

compiler/rustc_ast_pretty/src/pp/ring.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ impl<T> RingBuffer<T> {
3232
index
3333
}
3434

35-
pub fn advance_left(&mut self) {
36-
self.data.pop_front().unwrap();
37-
self.offset += 1;
38-
}
39-
4035
pub fn clear(&mut self) {
4136
self.data.clear();
4237
}
@@ -53,6 +48,12 @@ impl<T> RingBuffer<T> {
5348
self.data.front_mut()
5449
}
5550

51+
pub fn pop_first(&mut self) -> Option<T> {
52+
let first = self.data.pop_front()?;
53+
self.offset += 1;
54+
Some(first)
55+
}
56+
5657
pub fn last(&self) -> Option<&T> {
5758
self.data.back()
5859
}

0 commit comments

Comments
 (0)