+1, also has the advantage of not being a quadratic allocator the way Jim's usage of apr_pstrcat is.
>________________________________ >From: Stefan Fritsch <s...@sfritsch.de> >To: dev@httpd.apache.org >Sent: Thursday, August 25, 2011 4:56 PM >Subject: Re: svn commit: r1161661 - >/httpd/httpd/trunk/modules/http/byterange_filter.c > >On Thu, 25 Aug 2011, j...@apache.org wrote: > >> Author: jim >> Date: Thu Aug 25 17:38:19 2011 >> New Revision: 1161661 >> >> URL: http://svn.apache.org/viewvc?rev=1161661&view=rev >> Log: >> Merge in byteranges >> >> Modified: >> httpd/httpd/trunk/modules/http/byterange_filter.c >> >> Modified: httpd/httpd/trunk/modules/http/byterange_filter.c >> URL: >> http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http/byterange_filter.c?rev=1161661&r1=1161660&r2=1161661&view=diff >> ============================================================================== >> --- httpd/httpd/trunk/modules/http/byterange_filter.c (original) >> +++ httpd/httpd/trunk/modules/http/byterange_filter.c Thu Aug 25 17:38:19 >> 2011 > > >> + if (in_merge) { >> + continue; >> + } else { >> + char *nr = apr_psprintf(r->pool, "%" APR_OFF_T_FMT "-%" >> APR_OFF_T_FMT, >> + ostart, oend); >> + merged = apr_pstrcat(r->pool, merged, (num_ranges++ ? "," : >> ""), nr, NULL); >> + } >> } >> >> + if (in_merge) { >> + char *nr = apr_psprintf(r->pool, "%" APR_OFF_T_FMT "-%" >> APR_OFF_T_FMT, >> + ostart, oend); >> + merged = apr_pstrcat(r->pool, merged, (num_ranges++ ? "," : ""), >> nr, NULL); >> + } > >Is it really a good idea to first parse the range string (involving lots of >copying with ap_getword), then format it back into a string just to have it >parsed by parse_byterange again? I would much prefer to have it parsed only >once into an array of values and then do the merging in that array. This is >more efficient and I think it would also lead to better readability. My >original patch for merging/sorting had some code for that which we could reuse: > >http://mail-archives.apache.org/mod_mbox/httpd-dev/201108.mbox/%3c201108240028.03308...@sfritsch.de%3E > > > >