Geoffrey Young wrote: [...]
Index: xs/APR/Brigade/APR__Brigade.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/APR/Brigade/APR__Brigade.h,v
retrieving revision 1.4
diff -u -r1.4 APR__Brigade.h
--- xs/APR/Brigade/APR__Brigade.h 29 Mar 2002 16:16:43 -0000 1.4
+++ xs/APR/Brigade/APR__Brigade.h 20 Jan 2004 18:54:10 -0000
@@ -67,3 +67,35 @@
return APR_BRIGADE_EMPTY(brigade);
}
+static MP_INLINE
+SV *mpxs_APR__Brigade_length(pTHX_ apr_bucket_brigade *bb,
+ int read_all)
+{
+ apr_off_t length;
+
+ apr_status_t rv = apr_brigade_length(bb, read_all, &length);
+
+ if (rv == APR_SUCCESS) {
+ return newSViv((int)length);
+ }
+
+ return &PL_sv_undef;
+}
won't it be better to die if it fails and stick rv into [EMAIL PROTECTED] e.g. if you try to read a bucket which has no data? Just thinking aloud here, we have many places where don't quite handle error codes, but I tend to at least stick XXX in them and hopefully figure it out when we get first failures.
+static MP_INLINE +apr_status_t mpxs_apr_brigade_flatten(pTHX_ apr_bucket_brigade *bb, + SV *sv_buf, SV *sv_len) +{ + apr_status_t status; + apr_size_t len = mp_xs_sv2_apr_size_t(sv_len); + + mpxs_sv_grow(sv_buf, len); + status = apr_brigade_flatten(bb, SvPVX(sv_buf), &len); + mpxs_sv_cur_set(sv_buf, len); + + if (!SvREADONLY(sv_len)) { + sv_setiv(sv_len, len); + } + + return status; +}
In the test script you end up allocating memory for 300k instead of 200k, just to throw 100k of it right away. a big waste.
I don't think flatten is effective, as it has to go through all the bucket twice - once because you need to figure out its length, second time to slurp data.
pflatten doesn't require that. It does all the work for you. You really want to use flatten only when you want to flatten only not more than X bytes, I think.
with pflatten you do:
char *buffer; apr_size_t bufsiz = HUGE_STRING_LEN; rc = apr_brigade_pflatten(bb, &buffer, &bufsiz, pool);
buffer is probably PVX(sv_buf), after you forced it into PV.
and after that set the pv's length slot to bufsize.
and then just stash that buffer into a new SV or pass. More effecient and simpler for the end user (though requires the dreaded pool object)
__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]