apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@everythingsucks.co.uk
Subject UPDATE: [Patch] poll/unix/poll.c:apr_pollset_poll() optimisation
Date Thu, 05 Jan 2006 00:29:03 GMT
Greetings,

There's a sneakier (and pretty obvious, once you look at it) way of 
improving this loop which I prefer to my original mail by replacing the 
for-loop condition.

Should be safe: I like poll()... he has an honest face... I don't think 
he will lie to us about the number of signalled descriptors.


--- poll.c      2006/01/02 18:30:27     1.1
+++ poll.c      2006/01/05 00:11:36
@@ -254,13 +254,13 @@
         return apr_get_netos_error();
     }
     if (rv == 0) {
         return APR_TIMEUP;
     }
     j = 0;
-    for (i = 0; i < pollset->nelts; i++) {
+    for (i = 0; j < rv; i++) {
         if (pollset->pollset[i].revents != 0) {
             pollset->result_set[j] = pollset->query_set[i];
             pollset->result_set[j].rtnevents =
                 get_revent(pollset->pollset[i].revents);
             j++;
         }



Cheers
Gerry Calderhead

Quoting gerry@everythingsucks.co.uk:

> Greetings,
>
> Spotted an early-exit optimisation in poll/unix/poll.c:apr_pollset_poll().
>
> We know the number of signalled descriptors, NUM, returned from the 
> poll() call so we could bust out of the post-processing loop once 
> we've added NUM signalled descriptors to our RESULT_SET.
>
> Cheers
> Gerry Calderhead
>
> [gerry@devbox unix]$ rcsdiff -u6 poll.c
> ===================================================================
> RCS file: RCS/poll.c,v
> retrieving revision 1.1
> diff -u6 -r1.1 poll.c
> --- poll.c      2006/01/02 18:30:27     1.1
> +++ poll.c      2006/01/02 20:16:14
> @@ -259,13 +259,13 @@
>     j = 0;
>     for (i = 0; i < pollset->nelts; i++) {
>         if (pollset->pollset[i].revents != 0) {
>             pollset->result_set[j] = pollset->query_set[i];
>             pollset->result_set[j].rtnevents =
>                 get_revent(pollset->pollset[i].revents);
> -            j++;
> +            if ((++j)==(*num)) break;
>         }
>     }
>     if (descriptors)
>         *descriptors = pollset->result_set;
>     return APR_SUCCESS;
> }
>
>




Mime
View raw message