From 10f82355f53dbe41a9261baacc02f962ecba60f8 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Mon, 24 Feb 2025 15:24:59 +0000 Subject: [PATCH] txCommands.c TxGetInputEvent() rework main loop to iterate less Original version would iterate exhaustively, even when it was not necessary. This version seeks to do the minimum amount of iteration work based on the information available. --- textio/txCommands.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/textio/txCommands.c b/textio/txCommands.c index cc71bc35..5e05a5f3 100644 --- a/textio/txCommands.c +++ b/textio/txCommands.c @@ -1021,22 +1021,33 @@ TxGetInputEvent( perror("magic"); } - for (i = 0; numReady && i < txLastInputEntry; i++) + /* 0..1023 using numReady==0 to terminate early */ + for (fd = 0; numReady && fd <= txInputDescriptors_nfds; fd++) { - /* This device has data on its file descriptor, call - * it so that it can add events to the input queue. - */ - for (fd = 0; fd <= txInputDescriptors_nfds; fd++) { - if (FD_ISSET(fd, &inputs) && - FD_ISSET(fd, &txInputDevice[i].tx_fdmask)) { - lastNum = txNumInputEvents; - (*(txInputDevice[i].tx_inputProc)) - (fd, txInputDevice[i].tx_cdata); /** @invoke cb_textio_input_t */ - FD_CLR(fd, &inputs); - /* Did this driver choose to add an event? */ - if (txNumInputEvents != lastNum) gotSome = TRUE; - numReady--; - } + if (!FD_ISSET(fd, &inputs)) + continue; /* this fd is was not monitored or is not ready */ + + /* find the input device receiver entry */ + for (i = 0; i < txLastInputEntry; i++) + { + if (!FD_ISSET(fd, &txInputDevice[i].tx_fdmask)) + continue; + + /* This device has data on its file descriptor, call + * it so that it can add events to the input queue. + */ + lastNum = txNumInputEvents; + + (*txInputDevice[i].tx_inputProc)(fd, txInputDevice[i].tx_cdata); + + /* Did this driver choose to add an event? */ + if (txNumInputEvents != lastNum) gotSome = TRUE; + numReady--; + + /* original code would FD_CLR() which would effectively break here + * so this only allows the first found receiver to receive the data + */ + break; } } /*