diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2025-02-03 07:36:42 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2025-02-03 07:47:41 +0200 |
commit | 2c2d1f5efaeb6b6c06c7b0d7f79fb83381e8c8c5 (patch) | |
tree | 715b0f328e12d623a4fb3846d99644bd9ec3a835 | |
parent | 4242f5ddeee005ef944f72ac313887b6221a31a1 (diff) |
Optimize standalone true/false builtin calls in script
-rw-r--r-- | libbuild2/script/run.cxx | 22 | ||||
-rw-r--r-- | libbuild2/script/run.hxx | 2 |
2 files changed, 22 insertions, 2 deletions
diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index b7e8b27..99f4c97 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -1813,6 +1813,24 @@ namespace build2 // const string& program (c.program.recall.string ()); + // Optimize standalone true/false builtins (used in conditions, etc). We + // know they don't read/write stdin/stdout/stderr so none of the below + // complications are necessary. + // + if (resolve && (program == "true" || program == "false") && + first && last && cf == nullptr && + !c.in && !c.out && !c.err && !c.exit) + { + // Note: we can safely ignore agruments, env vars, and timeout. + // + // Don't print the true and false builtins, since they are normally + // used for the commands execution flow control (also below). + // + return program == "true"; + } + + // Standard streams. + // const redirect& in ((c.in ? *c.in : env.in).effective ()); const redirect* out (!last || (cf != nullptr && !last_cmd) @@ -2757,7 +2775,7 @@ namespace build2 // Execute the builtin. // // Don't print the true and false builtins, since they are normally - // used for the commands execution flow control. + // used for the commands execution flow control (also above). // if (verb >= 2 && program != "true" && program != "false") print_process (args); @@ -3263,6 +3281,8 @@ namespace build2 const function<command_function>& cf, bool last_cmd) { + assert (last_cmd || cf != nullptr); + // Note that we don't print the expression at any verbosity level // assuming that the caller does this, potentially providing some // additional information (command type, etc). diff --git a/libbuild2/script/run.hxx b/libbuild2/script/run.hxx index c4c2aa2..aa11def 100644 --- a/libbuild2/script/run.hxx +++ b/libbuild2/script/run.hxx @@ -39,7 +39,7 @@ namespace build2 // can be used in diagnostics. // // Optionally, execute the specified function at the end of the pipe, - // either after the last command or instead of it. + // either after the last command or instead of it (last_cmd=false). // void run (environment&, |