summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Brown <kbrown@cornell.edu>2020-11-19 15:22:56 -0500
committerKen Brown <kbrown@cornell.edu>2020-11-19 15:22:56 -0500
commit11c5fd6abde05956f909729289883599392c39a2 (patch)
tree48c75ab77e17f5fa82f088abfa3ffaabc163d67b
parent9ea6f38dea380cf9b7cb2df2a78e65b47b32c043 (diff)
downloadcygnal-11c5fd6abde05956f909729289883599392c39a2.tar.gz
cygnal-11c5fd6abde05956f909729289883599392c39a2.tar.bz2
cygnal-11c5fd6abde05956f909729289883599392c39a2.zip
Cygwin: fhandler_fifo::cleanup_handlers: improve efficiency
Traverse the fifo_client_handler list from the top down to try to avoid copying.
-rw-r--r--winsup/cygwin/fhandler_fifo.cc13
1 files 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. */