Skip to content

Commit 9f60fca

Browse files
committed
Simplify line splitting code in exec_with_streaming NFC
1 parent af6d540 commit 9f60fca

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

crates/cargo-util/src/process_builder.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -256,34 +256,30 @@ impl ProcessBuilder {
256256
None => return,
257257
}
258258
};
259-
{
260-
// scope for new_lines
261-
let new_lines = if capture_output {
262-
let dst = if is_out { &mut stdout } else { &mut stderr };
263-
let start = dst.len();
264-
let data = data.drain(..idx);
265-
dst.extend(data);
266-
&dst[start..]
259+
260+
let new_lines = &data[..idx];
261+
262+
for line in String::from_utf8_lossy(new_lines).lines() {
263+
if callback_error.is_some() {
264+
break;
265+
}
266+
let callback_result = if is_out {
267+
on_stdout_line(line)
267268
} else {
268-
&data[..idx]
269+
on_stderr_line(line)
269270
};
270-
for line in String::from_utf8_lossy(new_lines).lines() {
271-
if callback_error.is_some() {
272-
break;
273-
}
274-
let callback_result = if is_out {
275-
on_stdout_line(line)
276-
} else {
277-
on_stderr_line(line)
278-
};
279-
if let Err(e) = callback_result {
280-
callback_error = Some(e);
281-
}
271+
if let Err(e) = callback_result {
272+
callback_error = Some(e);
273+
break;
282274
}
283275
}
284-
if !capture_output {
285-
data.drain(..idx);
276+
277+
if capture_output {
278+
let dst = if is_out { &mut stdout } else { &mut stderr };
279+
dst.extend(new_lines);
286280
}
281+
282+
data.drain(..idx);
287283
})?;
288284
child.wait()
289285
})()

0 commit comments

Comments
 (0)