From: Ken Brown Date: Thu, 19 Nov 2020 20:22:56 +0000 (-0500) Subject: Cygwin: fhandler_fifo::cleanup_handlers: improve efficiency X-Git-Tag: newlib-4.1.0~37 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=11c5fd6abde05956f909729289883599392c39a2;p=newlib-cygwin.git Cygwin: fhandler_fifo::cleanup_handlers: improve efficiency Traverse the fifo_client_handler list from the top down to try to avoid copying. --- 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. */