httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cliff Woolley <>
Subject Re: [PATCH] Avoid unnecessary brigade splits on core input and output filters. WAS: EOS or FLUSH buckets
Date Thu, 12 Jun 2003 21:55:10 GMT

> > On Thu, 12 Jun 2003, Justin Erenkrantz wrote:
> >
> > > for (bucket = APR_BUCKET_FIRST(ctx->b);
> > >      bucket != e && bucket != APR_BRIGADE_LAST(ctx->b);
> > >      bucket = APR_BUCKET_NEXT(bucket)) {
> > >    apr_bucket_remove(bucket);
> > >    APR_BRIGADE_INSERT_TAIL(b, bucket);
> > > }

PS: if you *were* going to write it this way, then it would actually be:

for (bucket = APR_BRIGADE_FIRST(ctx->b);
     bucket != e && bucket != APR_BRIGADE_SENTINEL(ctx->b);
     bucket = APR_BRIGADE_FIRST(ctx->b))

The second line has to test against the sentinel, not APR_BRIGADE_LAST(),
because otherwise the last bucket in the brigade could never be copied.
The third line has to always use APR_BRIGADE_FIRST(), because after an
iteration of the loop, APR_BUCKET_NEXT(bucket) now points to
APR_BRIGADE_SENTINEL(b) [since bucket is now the last bucket in b], not to
the bucket you really want, which is the one that's now the first bucket
in ctx->b.

I should point out that the above code does one thing that my code does
not: it allows for bucket e to be completely absent from ctx->b.  (In
which case ctx->b would be left completely empty at the end of the loop.)
My code assumes that e is guaranteed to be somewhere in brigade ctx->b.
(In which case ctx->b will have at least one bucket (e) left in it at the
end of the loop.)


View raw message