mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
optimize extpoll fd delete
Previous method of shifting back array by one to cover the deleted item could be expensive when the list was large and the deleted item appeared early in it. This scheme swaps the last guy into the vacant space and reduces the list size by one. (AG adapted for style and not to care if n is end guy) Signed-off-by: Edwin van der Oetelaar <oetelaar.automatisering@gmail.com> Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
73abc25cb5
commit
5e59bf15e1
1 changed files with 12 additions and 7 deletions
|
@ -139,13 +139,18 @@ static int callback_http(struct libwebsocket_context * this,
|
|||
break;
|
||||
|
||||
case LWS_CALLBACK_DEL_POLL_FD:
|
||||
for (n = 0; n < count_pollfds; n++)
|
||||
if (pollfds[n].fd == (int)(long)user)
|
||||
while (n < count_pollfds) {
|
||||
pollfds[n] = pollfds[n + 1];
|
||||
n++;
|
||||
}
|
||||
count_pollfds--;
|
||||
for (n = 0; n < count_pollfds; n++) {
|
||||
if (pollfds[n].fd != (int)(long)user)
|
||||
continue;
|
||||
/*
|
||||
* swap the end guy into our vacant slot...
|
||||
* works ok if n is the end guy
|
||||
*/
|
||||
pollfds[n] = pollfds[count_pollfds - 1];
|
||||
pollfds[count_pollfds - 1].fd = -1;
|
||||
count_pollfds--;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LWS_CALLBACK_SET_MODE_POLL_FD:
|
||||
|
|
Loading…
Add table
Reference in a new issue