Hi everyone,
My output filter module is finished and seems to be running along nicely
in production. I have a couple areas where I thought it could be
optimized, but I need some input from the list.
First, the module reads through the content looking for matches to a
configured string (literal, no regex). It then inserts content
before|after or replaces the search string with content from a file, or
content given in the config. It can be configured to do this on first
match, or globally.
Also, several rules can be configured. e.g.
MyInsertRule after "<head>" file "conf/insert.html" once
MyInsertRule replace "<body>" string "<body id=\"foo\">" once
MyInsertRule before "bar" string "foo" globally
I loop through all buckets for each rule, so 3 rules would mean 3
passes. In any case, my issue is the same with only 1 rule.
I have this algorithm that, as I'm going through the buckets, finds the
largest possible partial match at the end of a bucket, and snips it off
(saving it within ctx->tail_str incase we're at the end of a brigade).
At the top of my bucket loop, if I have a tail_str, I split off the
largest possible partial match from the next bucket and append it to the
tail_str, create a new bucket from it, insert it in the brigade, and
then read and operate on it. (Things get a bit more complicated, but
that's the general idea.)
This works fine except that I end up with buckets containing short
fragments (which explains the complication mentioned above on multi-rule
configs).
I thought it would be better to test the length of the bucket I get at
the top of the loop and append it in whole. The problem is that I'm not
sure what the maximum length is for bucket data.
I see in apr_buckets.h:
/** default bucket buffer size - 8KB minus room for memory allocator
headers */
#define APR_BUCKET_BUFF_SIZE 8000
So, how do I calculate how much the bucket can hold? What is the size
of the memory allocator headers?
Any other feedback is also appreciated.
Thanks,
--
Drew