Skip to content

Commit 65dd670

Browse files
committed
Touch up print_string
1 parent d5f15a8 commit 65dd670

File tree

1 file changed

+4
-5
lines changed
  • compiler/rustc_ast_pretty/src

1 file changed

+4
-5
lines changed

compiler/rustc_ast_pretty/src/pp.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ mod ring;
137137
use ring::RingBuffer;
138138
use std::borrow::Cow;
139139
use std::collections::VecDeque;
140+
use std::iter;
140141

141142
/// How to break. Described in more detail in the module docs.
142143
#[derive(Clone, Copy, PartialEq)]
@@ -425,20 +426,18 @@ impl Printer {
425426
}
426427

427428
fn print_string(&mut self, string: &str) {
428-
let len = string.len() as isize;
429-
// assert!(len <= space);
430-
self.space -= len;
431-
432429
// Write the pending indent. A more concise way of doing this would be:
433430
//
434431
// write!(self.out, "{: >n$}", "", n = self.pending_indentation as usize)?;
435432
//
436433
// But that is significantly slower. This code is sufficiently hot, and indents can get
437434
// sufficiently large, that the difference is significant on some workloads.
438435
self.out.reserve(self.pending_indentation as usize);
439-
self.out.extend(std::iter::repeat(' ').take(self.pending_indentation as usize));
436+
self.out.extend(iter::repeat(' ').take(self.pending_indentation as usize));
440437
self.pending_indentation = 0;
438+
441439
self.out.push_str(string);
440+
self.space -= string.len() as isize;
442441
}
443442

444443
// Convenience functions to talk to the printer.

0 commit comments

Comments
 (0)