diff options
| author | Shotaro Yamada <sinkuu@sinkuu.xyz> | 2018-10-10 10:50:25 +0900 |
|---|---|---|
| committer | Shotaro Yamada <sinkuu@sinkuu.xyz> | 2018-10-15 23:59:08 +0900 |
| commit | 6380f885278e33ff058e01555538ced58c44dacf (patch) | |
| tree | b2929ed708ac01b70ec685de7f607aa02df2b7cb | |
| parent | 751bcf5fa08ee5c5ba156e43c7f8327f7968b02f (diff) | |
Cleanup
| -rw-r--r-- | src/missed_spans.rs | 18 | ||||
| -rw-r--r-- | src/string.rs | 4 |
2 files changed, 4 insertions, 18 deletions
diff --git a/src/missed_spans.rs b/src/missed_spans.rs index f2f2295a872..b7d73bbf0ba 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -120,7 +120,7 @@ impl<'a> FmtVisitor<'a> { } fn push_vertical_spaces(&mut self, mut newline_count: usize) { - let offset = self.count_trailing_newlines(); + let offset = self.buffer.chars().rev().take_while(|c| *c == '\n').count(); let newline_upper_bound = self.config.blank_lines_upper_bound() + 1; let newline_lower_bound = self.config.blank_lines_lower_bound() + 1; @@ -142,16 +142,6 @@ impl<'a> FmtVisitor<'a> { self.push_str(&blank_lines); } - fn count_trailing_newlines(&self) -> usize { - let mut buf = &*self.buffer; - let mut result = 0; - while buf.ends_with('\n') { - buf = &buf[..buf.len() - 1]; - result += 1; - } - result - } - fn write_snippet<F>(&mut self, span: Span, process_last_snippet: F) where F: Fn(&mut FmtVisitor, &str, &str), @@ -271,11 +261,7 @@ impl<'a> FmtVisitor<'a> { if let Some('/') = subslice.chars().nth(1) { // check that there are no contained block comments - if !subslice - .split('\n') - .map(|s| s.trim_left()) - .any(|s| s.len() >= 2 && &s[0..2] == "/*") - { + if !subslice.lines().any(|s| s.trim_left().starts_with("/*")) { // Add a newline after line comments self.push_str("\n"); } diff --git a/src/string.rs b/src/string.rs index ca063123e39..b70f9f0f12b 100644 --- a/src/string.rs +++ b/src/string.rs @@ -242,9 +242,9 @@ fn break_string(max_chars: usize, trim_end: bool, line_end: &str, input: &[&str] for (i, grapheme) in input[0..=index].iter().enumerate() { if is_line_feed(grapheme) { if i <= index_minus_ws { - let mut line = input[0..i].join(""); + let mut line = &input[0..i].join("")[..]; if trim_end { - line = line.trim_right().to_string(); + line = line.trim_right(); } return SnippetState::EndWithLineFeed(format!("{}\n", line), i + 1); } |
