Omit check of a successive line in loop
I think that s == "" is the only edge case (as it makes iter.next() return None the first time). The early return is necessary so that the last character of 'out' isn't popped if s == "" && !frag.need_backline
This commit is contained in:
parent
41c3017c82
commit
38167a806c
1 changed files with 10 additions and 6 deletions
|
|
@ -939,7 +939,13 @@ crate enum DocFragmentKind {
|
|||
// `need_backline` field).
|
||||
fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
|
||||
let s = frag.doc.as_str();
|
||||
let mut iter = s.lines().peekable();
|
||||
let mut iter = s.lines();
|
||||
if s == "" {
|
||||
if frag.need_backline {
|
||||
out.push('\n');
|
||||
}
|
||||
return;
|
||||
}
|
||||
while let Some(line) = iter.next() {
|
||||
if line.chars().any(|c| !c.is_whitespace()) {
|
||||
assert!(line.len() >= frag.indent);
|
||||
|
|
@ -947,13 +953,11 @@ fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
|
|||
} else {
|
||||
out.push_str(line);
|
||||
}
|
||||
if iter.peek().is_some() {
|
||||
out.push('\n');
|
||||
}
|
||||
}
|
||||
if frag.need_backline {
|
||||
out.push('\n');
|
||||
}
|
||||
if !frag.need_backline {
|
||||
out.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/// Collapse a collection of [`DocFragment`]s into one string,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue