From 9275d965a6952d44035fd0502ee0d3991352c460 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 26 Aug 2024 21:00:08 +1000 Subject: Do not gather full input data in a single string when piping Refactor ShellManager and pipe to feed lines from the buffer directly, this should reduce memory use when piping big chunks of buffers. The pipe output is still provided as a single big buffer. --- src/shell_manager.hh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/shell_manager.hh') diff --git a/src/shell_manager.hh b/src/shell_manager.hh index f6ef38a4..3dc62e0a 100644 --- a/src/shell_manager.hh +++ b/src/shell_manager.hh @@ -58,10 +58,20 @@ public: friend constexpr bool with_bit_ops(Meta::Type) { return true; } std::pair eval(StringView cmdline, const Context& context, - StringView input = {}, + FunctionRef stdin_generator, Flags flags = Flags::WaitForStdout, const ShellContext& shell_context = {}); + std::pair eval(StringView cmdline, const Context& context, + StringView stdin, + Flags flags = Flags::WaitForStdout, + const ShellContext& shell_context = {}) + { + return eval(cmdline, context, + [stdin]() mutable { return std::exchange(stdin, StringView{}); }, + flags, shell_context); + } + Shell spawn(StringView cmdline, const Context& context, bool open_stdin, -- cgit v1.2.3