diff options
| author | David Tolnay <dtolnay@gmail.com> | 2022-01-19 18:35:02 -0800 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2022-01-19 19:02:25 -0800 |
| commit | d981c5b354c40a6097c83a72173ae8a5569db2e1 (patch) | |
| tree | 9c56b841d9c274bd5e0a71ae0324ffe8451a61cc | |
| parent | d81740ed2a63d377a725b0fbf935c391f5c7eb5e (diff) | |
| download | rust-d981c5b354c40a6097c83a72173ae8a5569db2e1.tar.gz rust-d981c5b354c40a6097c83a72173ae8a5569db2e1.zip | |
Eliminate a token clone from advance_left
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pp.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pp/ring.rs | 11 |
2 files changed, 7 insertions, 7 deletions
diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs index 0e3e7909afb..b93463e99fd 100644 --- a/compiler/rustc_ast_pretty/src/pp.rs +++ b/compiler/rustc_ast_pretty/src/pp.rs @@ -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, @@ -335,7 +335,6 @@ impl Printer { self.left_total += len; - self.buf.advance_left(); if self.buf.is_empty() { break; } diff --git a/compiler/rustc_ast_pretty/src/pp/ring.rs b/compiler/rustc_ast_pretty/src/pp/ring.rs index d20142eb591..8187394fe30 100644 --- a/compiler/rustc_ast_pretty/src/pp/ring.rs +++ b/compiler/rustc_ast_pretty/src/pp/ring.rs @@ -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(); } @@ -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() } |
