From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id 9AFAC3857C7E; Fri, 20 Nov 2020 13:33:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9AFAC3857C7E Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: fhandler_fifo::cleanup_handlers: improve efficiency X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 9ea6f38dea380cf9b7cb2df2a78e65b47b32c043 X-Git-Newrev: 11c5fd6abde05956f909729289883599392c39a2 Message-Id: <20201120133341.9AFAC3857C7E@sourceware.org> Date: Fri, 20 Nov 2020 13:33:41 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Nov 2020 13:33:41 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=11c5fd6abde05956f909729289883599392c39a2 commit 11c5fd6abde05956f909729289883599392c39a2 Author: Ken Brown Date: Thu Nov 19 15:22:56 2020 -0500 Cygwin: fhandler_fifo::cleanup_handlers: improve efficiency Traverse the fifo_client_handler list from the top down to try to avoid copying. Diff: --- winsup/cygwin/fhandler_fifo.cc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index eff05d242..8b67037cb 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -395,15 +395,10 @@ fhandler_fifo::delete_client_handler (int i) void fhandler_fifo::cleanup_handlers () { - int i = 0; - - while (i < nhandlers) - { - if (fc_handler[i].get_state () < fc_connected) - delete_client_handler (i); - else - i++; - } + /* Work from the top down to try to avoid copying. */ + for (int i = nhandlers - 1; i >= 0; --i) + if (fc_handler[i].get_state () < fc_connected) + delete_client_handler (i); } /* Always called with fifo_client_lock in place. */