Re: pseudo-specs for a String class

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Mon, 01 Sep 2008 16:27:59 -0600

On Sun, 2008-08-31 at 22:40 +0200, Kinkie wrote:
> On Sun, Aug 31, 2008 at 6:00 PM, Adrian Chadd <adrian_at_squid-cache.org> wrote:
> > Do you really want to provide a 'consume' interface for a low-level
> > representation of memory?
> >
> > I think trying to replace MemBuf with this new buffer is a bit silly.
> > Sure, use it -in- MemBuf, along with all the other places that buffers
> > are used.
> >
> > What about strtok()? Why would you want to tokenise data?
>
> I'd like it to be used
> - everywhere MemBuf is used
> - everywhere a char* is used for a string
> - strtok, strchr, strstr, etc to be used in the HTTP parser
>
> All of the above with increased efficiency both in terms callers' LOC
> and performance.

> Given:
> KBuf src="GET http://some.url/ HTTP/1.0\r\nHost: some.url\r\n\r\n"
> KBuf out;
>
> The following are expected to be equivalent:
> ====
> u_int32_t pos=src.index('\n');
> out=src.substr(0,pos);
> src=src.substr(pos,-1); //to end-of-string
> ====
> out=src.consume(src.index('\n'));
> ====
> out=src.nextToken('\n');
> ====

IMO, manipulations like the above should be done in a String class that
uses a low-level Buffer. This would yield same callers LOC (not that I
care much about that) and the same performance as your solution, but
would allow us to separate the two rather different concepts and
optimize/extend each separately.

Thank you,

Alex.
Received on Mon Sep 01 2008 - 22:28:29 MDT

This archive was generated by hypermail 2.2.0 : Tue Sep 02 2008 - 12:00:02 MDT