On Thu, Jun 12, 2003 at 05:07:32PM -0400, Cliff Woolley wrote:
> 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);
> > }
> 
> No!  Bad!!  The whole beauty of the ring data structure is that all of
> these operations can be done in constant time, no loops.  Bear with me,
> and I'll explain.

Heh.  I didn't say it was optimal, but that's the code I'd write.  But,
if APR_RING_SPLICE_TAIL can produce equivalent results, then great.

> if (APR_BRIGADE_FIRST(ctx->b) != e)
> {
>     /* move the sequence into the new brigade */
>     APR_RING_SPLICE_TAIL(&b->list,
>                          APR_BRIGADE_FIRST(ctx->b),
>                          APR_BUCKET_PREV(e),
>                          apr_bucket, link);
> 
>     /* fixup the dangling pointers in ctx->b */
>     APR_BRIGADE_FIRST(ctx->b) = e;
>     APR_BUCKET_PREV(e) = APR_BRIGADE_SENTINEL(ctx->b);
> }

I suggest that this be created as a macro called
APR_BRIGADE_CONCAT_UNTIL() as I don't think understanding apr_ring.h
should be a pre-req for writing filters.  ;-)   -- justin

Reply via email to