--------------------- PatchSet 10192 Date: 2007/12/03 08:54:28 Author: adri Branch: s27_adri Tag: (none) Log: A precursor to playing with ref-counted underlying string buffers for copy-on-write string stuff. * Implement a 'better Dup' which doesn't involve strlen. Why oh why is strlen involved when copying one String to another String.. * Use stringDup() in the header entry initialisation function; this should result in stringDup() being called in the header entry cloning path. Members: libbuf/String.c:1.1.2.1->1.1.2.2 src/HttpHeader.c:1.28.6.1->1.28.6.1.4.1 Index: squid/libbuf/String.c =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/String.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/libbuf/String.c 3 Dec 2007 07:59:25 -0000 1.1.2.1 +++ squid/libbuf/String.c 3 Dec 2007 08:54:28 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: String.c,v 1.1.2.1 2007/12/03 07:59:25 adri Exp $ + * $Id: String.c,v 1.1.2.2 2007/12/03 08:54:28 adri Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -65,6 +65,16 @@ } void +stringInitStr(String *s, const String *src) +{ + assert(s); + if (src == NULL) + *s = StringNull; + else + stringLimitInit(s, strBuf(*src), strLen(*src)); +} + +void stringLimitInit(String * s, const char *str, int len) { assert(s && str); @@ -79,7 +89,7 @@ { String dup; assert(s); - stringInit(&dup, s->nbuf); + stringInitStr(&dup, s); return dup; } Index: squid/src/HttpHeader.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpHeader.c,v retrieving revision 1.28.6.1 retrieving revision 1.28.6.1.4.1 diff -u -r1.28.6.1 -r1.28.6.1.4.1 --- squid/src/HttpHeader.c 27 Nov 2007 08:12:23 -0000 1.28.6.1 +++ squid/src/HttpHeader.c 3 Dec 2007 08:54:28 -0000 1.28.6.1.4.1 @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.c,v 1.28.6.1 2007/11/27 08:12:23 adri Exp $ + * $Id: HttpHeader.c,v 1.28.6.1.4.1 2007/12/03 08:54:28 adri Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -1228,8 +1228,8 @@ if (id != HDR_OTHER) e->name = Headers[id].name; else - stringLimitInit(&e->name, strBuf(name), strLen(name)); - stringLimitInit(&e->value, strBuf(value), strLen(value)); + e->name = stringDup(&name); + e->value = stringDup(&value); Headers[id].stat.aliveCount++; debug(55, 9) ("created entry %p: '%s: %s'\n", e, strBuf(e->name), strBuf(e->value)); return e;