Change the ignore command to use drain() instead of collecting a value (#12120)

# Description

Change the `ignore` command to use `drain()` instead of collecting a
value.

This saves memory usage when piping a lot of output to `ignore`. There's
no reason to keep the output in memory if it's going to be discarded
anyway.

# User-Facing Changes
Probably none

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
This commit is contained in:
Devyn Cairns 2024-03-07 23:18:26 -08:00 committed by GitHub
parent 229e8c5fd7
commit 65af572761
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View File

@ -32,20 +32,20 @@ impl Command for Ignore {
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
input.into_value(call.head);
input.drain()?;
Ok(PipelineData::empty())
}
fn run_const(
&self,
_working_set: &StateWorkingSet,
call: &Call,
_call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
input.into_value(call.head);
input.drain()?;
Ok(PipelineData::empty())
}

View File

@ -0,0 +1,7 @@
use nu_test_support::nu;
#[test]
fn ignore_still_causes_stream_to_be_consumed_fully() {
let result = nu!("[foo bar] | each { |val| print $val; $val } | ignore");
assert_eq!("foobar", result.out);
}

View File

@ -45,6 +45,7 @@ mod hash_;
mod headers;
mod help;
mod histogram;
mod ignore;
mod insert;
mod inspect;
mod interleave;