From 521d0e84f5d435afcf0c0d7fb1a58ffce048f35f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 10 Nov 2019 13:33:20 -0800 Subject: [PATCH] Remove non-const get_io_for_fd These could be made unused. --- src/exec.cpp | 8 ++++---- src/io.cpp | 13 ------------- src/io.h | 2 -- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index 27f2101c1..58c6cf9dd 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -76,7 +76,7 @@ void exec_close(int fd) { } /// Returns true if the redirection is a file redirection to a file other than /dev/null. -static bool redirection_is_to_real_file(const shared_ptr &io) { +static bool redirection_is_to_real_file(const shared_ptr &io) { bool result = false; if (io && io->io_mode == io_mode_t::file) { // It's a file redirection. Compare the path to /dev/null. @@ -594,8 +594,8 @@ static bool handle_builtin_output(parser_t &parser, const std::shared_ptr // We will try to elide constructing an internal process. However if the output is going to a // real file, we have to do it. For example in `echo -n > file.txt` we proceed to open file.txt // even though there is no output, so that it is properly truncated. - const shared_ptr stdout_io = io_chain->get_io_for_fd(STDOUT_FILENO); - const shared_ptr stderr_io = io_chain->get_io_for_fd(STDERR_FILENO); + const shared_ptr stdout_io = io_chain->get_io_for_fd(STDOUT_FILENO); + const shared_ptr stderr_io = io_chain->get_io_for_fd(STDERR_FILENO); bool must_use_process = redirection_is_to_real_file(stdout_io) || redirection_is_to_real_file(stderr_io); @@ -610,7 +610,7 @@ static bool handle_builtin_output(parser_t &parser, const std::shared_ptr // need for a similar check for stderr. bool stdout_done = false; if (stdout_io && stdout_io->io_mode == io_mode_t::bufferfill) { - auto stdout_buffer = static_cast(stdout_io.get())->buffer(); + auto stdout_buffer = static_cast(stdout_io.get())->buffer(); stdout_buffer->append_from_stream(stdout_stream); stdout_done = true; } diff --git a/src/io.cpp b/src/io.cpp index 620c627ac..a857170ca 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -337,20 +337,7 @@ shared_ptr io_chain_t::get_io_for_fd(int fd) const { return shared_ptr(); } -shared_ptr io_chain_t::get_io_for_fd(int fd) { - size_t idx = this->size(); - while (idx--) { - const shared_ptr &data = this->at(idx); - if (data->fd == fd) { - return data; - } - } - return shared_ptr(); -} - /// The old function returned the last match, so we mimic that. shared_ptr io_chain_get(const io_chain_t &src, int fd) { return src.get_io_for_fd(fd); } - -shared_ptr io_chain_get(io_chain_t &src, int fd) { return src.get_io_for_fd(fd); } diff --git a/src/io.h b/src/io.h index 0b18b0d18..7a754a7e8 100644 --- a/src/io.h +++ b/src/io.h @@ -336,12 +336,10 @@ class io_chain_t : public std::vector> { void append(const io_chain_t &chain); shared_ptr get_io_for_fd(int fd) const; - shared_ptr get_io_for_fd(int fd); }; /// Return the last io redirection in the chain for the specified file descriptor. shared_ptr io_chain_get(const io_chain_t &src, int fd); -shared_ptr io_chain_get(io_chain_t &src, int fd); /// Helper type returned from making autoclose pipes. struct autoclose_pipes_t {