--------------------- PatchSet 8559 Date: 2006/08/28 09:39:49 Author: adri Branch: parserwork Tag: (none) Log: Save on calling headersEnd() twice in the client-side reply path - once in clientBuildReply(), then once again in httpReplyParseStep(). clientBuildReply() already called headersEnd(); so its return value can be pushed down into httpReplyParse(). This reduces the number of calls of headersEnd() to one during request parsing and one during reply parsing. There's other instances of it in the code but they're not being tickled by this particular path (all memory hits, no server-side fetches or re-validation.) The pointer arithmetic and buffer arithmetic is a bit ugly but it has to be done. For now. Members: src/HttpReply.c:1.16.8.2->1.16.8.3 src/client_side.c:1.143.2.8->1.143.2.9 src/protos.h:1.122.2.4->1.122.2.5 Index: squid/src/HttpReply.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpReply.c,v retrieving revision 1.16.8.2 retrieving revision 1.16.8.3 diff -u -r1.16.8.2 -r1.16.8.3 --- squid/src/HttpReply.c 28 Aug 2006 08:26:07 -0000 1.16.8.2 +++ squid/src/HttpReply.c 28 Aug 2006 09:39:49 -0000 1.16.8.3 @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.c,v 1.16.8.2 2006/08/28 08:26:07 adri Exp $ + * $Id: HttpReply.c,v 1.16.8.3 2006/08/28 09:39:49 adri Exp $ * * DEBUG: section 58 HTTP Reply (Response) * AUTHOR: Alex Rousskov @@ -53,7 +53,7 @@ static void httpReplyDoDestroy(HttpReply * rep); static void httpReplyHdrCacheInit(HttpReply * rep); static void httpReplyHdrCacheClean(HttpReply * rep); -static int httpReplyParseStep(HttpReply * rep, const char *parse_start, size_t len, int atEnd); +static int httpReplyParseStep(HttpReply * rep, const char *parse_start, size_t len, int atEnd, ssize_t hend); static int httpReplyParseError(HttpReply * rep); static int httpReplyIsolateStart(const char **parse_start, const char **blk_start, const char **blk_end); static time_t httpReplyHdrExpirationTime(const HttpReply * rep); @@ -137,6 +137,16 @@ int httpReplyParse(HttpReply * rep, const char *buf, size_t end) { + return httpReplyParse2(rep, buf, end, -1); +} + +/* + * 'hend' is either the result from a previous 'headersEnd()' call, or -1 if + * unknown (and thus this routine has to do it.) + */ +int +httpReplyParse2(HttpReply * rep, const char *buf, size_t end, ssize_t hend) +{ /* * this extra buffer/copy will be eliminated when headers become * meta-data in store. Currently we have to xstrncpy the buffer @@ -152,7 +162,7 @@ memBufDefInit(&mb); memBufAppend(&mb, buf, end); memBufAppend(&mb, "\0", 1); - success = httpReplyParseStep(rep, mb.buf, mb.size, 0); + success = httpReplyParseStep(rep, mb.buf, end, 0, hend); memBufClean(&mb); return success == 1; } @@ -384,7 +394,7 @@ * -1 -- parse error */ static int -httpReplyParseStep(HttpReply * rep, const char *buf, size_t l, int atEnd) +httpReplyParseStep(HttpReply * rep, const char *buf, size_t len, int atEnd, ssize_t hend) { const char *parse_start = buf; const char *blk_start, *blk_end; @@ -406,7 +416,19 @@ } if (rep->pstate == psReadyToParseHeaders) { int he; - he = headersEnd(parse_start, l); + int l; + l = len - (parse_start - buf); + /* + * the len/hend point to the whole buffer length; but the above code + * has moved parse_start to be at the beginning of the header block. + * So we do the math here if we need to which should (hopefully!) make + * up for the sliding of parse_start .. + */ + if (hend > -1) { + he = hend - (parse_start - buf); + } else { + he = headersEnd(parse_start, l); + } if (!httpMsgIsolateHeaders(&parse_start, l, he, &blk_start, &blk_end)) { if (atEnd) blk_start = parse_start, blk_end = blk_start + strlen(blk_start); Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.143.2.8 retrieving revision 1.143.2.9 diff -u -r1.143.2.8 -r1.143.2.9 --- squid/src/client_side.c 27 Aug 2006 02:16:37 -0000 1.143.2.8 +++ squid/src/client_side.c 28 Aug 2006 09:39:49 -0000 1.143.2.9 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.143.2.8 2006/08/27 02:16:37 adri Exp $ + * $Id: client_side.c,v 1.143.2.9 2006/08/28 09:39:49 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -2010,7 +2010,7 @@ { HttpReply *rep = httpReplyCreate(); size_t k = headersEnd(buf, size); - if (k && httpReplyParse(rep, buf, k)) { + if (k && httpReplyParse2(rep, buf, k, (ssize_t) k)) { /* enforce 1.0 reply version */ httpBuildVersion(&rep->sline.version, 1, 0); /* do header conversions */ Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.122.2.4 retrieving revision 1.122.2.5 diff -u -r1.122.2.4 -r1.122.2.5 --- squid/src/protos.h 27 Aug 2006 02:16:37 -0000 1.122.2.4 +++ squid/src/protos.h 28 Aug 2006 09:39:49 -0000 1.122.2.5 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.122.2.4 2006/08/27 02:16:37 adri Exp $ + * $Id: protos.h,v 1.122.2.5 2006/08/28 09:39:49 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -476,6 +476,7 @@ extern void httpReplyReset(HttpReply * rep); /* parse returns -1,0,+1 on error,need-more-data,success */ extern int httpReplyParse(HttpReply * rep, const char *buf, size_t); +extern int httpReplyParse2(HttpReply * rep, const char *buf, size_t, ssize_t); extern void httpReplyPackInto(const HttpReply * rep, Packer * p); /* ez-routines */ /* mem-pack: returns a ready to use mem buffer with a packed reply */