From 50e53e788a5cd0d4bef665e0b6b8426902cbe681 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Thu, 20 Oct 2022 06:22:07 -0400 Subject: [PATCH] Simplify and reduce allocations in pipeline data loop (#6790) --- crates/nu-protocol/src/pipeline_data.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/crates/nu-protocol/src/pipeline_data.rs b/crates/nu-protocol/src/pipeline_data.rs index 6b5516fdc7..32665fe13a 100644 --- a/crates/nu-protocol/src/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline_data.rs @@ -185,29 +185,17 @@ impl PipelineData { PipelineData::ExternalStream { stdout: Some(s), .. } => { - let mut items = vec![]; + let mut output = String::new(); for val in s { match val { - Ok(val) => { - items.push(val); - } - Err(e) => { - return Err(e); - } + Ok(val) => match val.as_string() { + Ok(s) => output.push_str(&s), + Err(err) => return Err(err), + }, + Err(e) => return Err(e), } } - - let mut output = String::new(); - for item in items { - match item.as_string() { - Ok(s) => output.push_str(&s), - Err(err) => { - return Err(err); - } - } - } - Ok(output) } }