--------------------- PatchSet 10423 Date: 2008/01/21 03:50:23 Author: adri Branch: s27_adri Tag: (none) Log: Implement a static String dictionary to overcome my (current) lack of static String buffers. This saves on all the little String allocations which are done for fixed strings. This is similar to the stuff done in the http header routines for the well-known headers. Members: src/String.c:1.7.44.2->1.7.44.3 src/client_side.c:1.202.2.9.4.45->1.202.2.9.4.46 src/enums.h:1.62.2.1.4.4->1.62.2.1.4.5 src/http.c:1.63.2.3.4.32->1.63.2.3.4.33 src/main.c:1.80.2.1.4.6->1.80.2.1.4.7 src/protos.h:1.146.2.4.4.40->1.146.2.4.4.41 Index: squid/src/String.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/String.c,v retrieving revision 1.7.44.2 retrieving revision 1.7.44.3 diff -u -r1.7.44.2 -r1.7.44.3 --- squid/src/String.c 9 Dec 2007 04:55:21 -0000 1.7.44.2 +++ squid/src/String.c 21 Jan 2008 03:50:23 -0000 1.7.44.3 @@ -1,6 +1,6 @@ /* - * $Id: String.c,v 1.7.44.2 2007/12/09 04:55:21 adri Exp $ + * $Id: String.c,v 1.7.44.3 2008/01/21 03:50:23 adri Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -37,6 +37,9 @@ #include "squid.h" +String *dict_array = NULL; +int dict_size = 0; + static void stringStatsOutput(StoreEntry *e) { @@ -57,4 +60,37 @@ cachemgrRegister("strings", "String Statistics", stringStatsOutput, 0, 1); } +/* + * A static string dictionary. Useful everywhere where we have static strings. + */ +void +stringDictInit(void) +{ + stringDictAdd(STR_KEEPALIVE, "keep-alive"); + stringDictAdd(STR_ON, "On"); + stringDictAdd(STR_PROXY_SUPPORT, "Proxy-support"); + stringDictAdd(STR_SESSION_BASED_AUTHENTICATION, "Session-Based-Authentication"); + stringDictAdd(STR_CLOSE, "close"); + stringDictAdd(STR_CHUNKED, "chunked"); + stringDictAdd(STR_TEXT_HTML, "text/html"); + stringDictAdd(STR_TEXT_PLAIN, "text/plain"); + stringDictAdd(STR_STAR_STAR, "*/*"); +} + +void +stringDictAdd(int id, const char *str) +{ + if (dict_size <= id) { + dict_size = id + 16; + dict_array = realloc(dict_array, sizeof(String) * dict_size); + } + stringLimitInit(&dict_array[id], str, strlen(str)); +} + +String +stringDictGet(int id) +{ + assert(id <= dict_size); + return dict_array[id]; +} Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.202.2.9.4.45 retrieving revision 1.202.2.9.4.46 diff -u -r1.202.2.9.4.45 -r1.202.2.9.4.46 --- squid/src/client_side.c 20 Jan 2008 11:22:02 -0000 1.202.2.9.4.45 +++ squid/src/client_side.c 21 Jan 2008 03:50:24 -0000 1.202.2.9.4.46 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.202.2.9.4.45 2008/01/20 11:22:02 adri Exp $ + * $Id: client_side.c,v 1.202.2.9.4.46 2008/01/21 03:50:24 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1994,8 +1994,8 @@ } request->flags.must_keepalive = 1; if (!request->flags.accelerated && !request->flags.transparent) { - httpHeaderPutStr(hdr, HDR_PROXY_SUPPORT, "Session-Based-Authentication"); - httpHeaderPutStr(hdr, HDR_CONNECTION, "Proxy-support"); + httpHeaderPutString(hdr, HDR_PROXY_SUPPORT, stringDictGet(STR_SESSION_BASED_AUTHENTICATION)); + httpHeaderPutString(hdr, HDR_CONNECTION, stringDictGet(STR_PROXY_SUPPORT)); } break; } @@ -2041,7 +2041,7 @@ } /* Append Transfer-Encoding */ if (request->flags.chunked_response) { - httpHeaderPutStr(hdr, HDR_TRANSFER_ENCODING, "chunked"); + httpHeaderPutString(hdr, HDR_TRANSFER_ENCODING, stringDictGet(STR_CHUNKED)); } /* Append Via */ if (Config.onoff.via) { @@ -2057,11 +2057,11 @@ } /* Signal keep-alive if needed */ if (!request->flags.proxy_keepalive) - httpHeaderPutStr(hdr, HDR_CONNECTION, "close"); + httpHeaderPutString(hdr, HDR_CONNECTION, stringDictGet(STR_CLOSE)); else if (request->http_ver.major == 1 && request->http_ver.minor == 0) { - httpHeaderPutStr(hdr, HDR_CONNECTION, "keep-alive"); + httpHeaderPutString(hdr, HDR_CONNECTION, stringDictGet(STR_KEEPALIVE)); if (!(http->flags.accel || http->flags.transparent)) - httpHeaderPutStr(hdr, HDR_PROXY_CONNECTION, "keep-alive"); + httpHeaderPutString(hdr, HDR_PROXY_CONNECTION, stringDictGet(STR_KEEPALIVE)); } #if ADD_X_REQUEST_URI /* Index: squid/src/enums.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/enums.h,v retrieving revision 1.62.2.1.4.4 retrieving revision 1.62.2.1.4.5 diff -u -r1.62.2.1.4.4 -r1.62.2.1.4.5 --- squid/src/enums.h 15 Jan 2008 10:56:45 -0000 1.62.2.1.4.4 +++ squid/src/enums.h 21 Jan 2008 03:50:24 -0000 1.62.2.1.4.5 @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.62.2.1.4.4 2008/01/15 10:56:45 adri Exp $ + * $Id: enums.h,v 1.62.2.1.4.5 2008/01/21 03:50:24 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -632,4 +632,16 @@ ST_OP_CREATE } store_op_t; +typedef enum { + STR_KEEPALIVE = 0, + STR_ON, + STR_PROXY_SUPPORT, + STR_SESSION_BASED_AUTHENTICATION, + STR_CLOSE, + STR_CHUNKED, + STR_TEXT_HTML, + STR_TEXT_PLAIN, + STR_STAR_STAR +} StringDictEntries; + #endif /* SQUID_ENUMS_H */ Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.63.2.3.4.32 retrieving revision 1.63.2.3.4.33 diff -u -r1.63.2.3.4.32 -r1.63.2.3.4.33 --- squid/src/http.c 6 Jan 2008 09:19:53 -0000 1.63.2.3.4.32 +++ squid/src/http.c 21 Jan 2008 03:50:24 -0000 1.63.2.3.4.33 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.63.2.3.4.32 2008/01/06 09:19:53 adri Exp $ + * $Id: http.c,v 1.63.2.3.4.33 2008/01/21 03:50:24 adri Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -1411,9 +1411,9 @@ /* maybe append Connection: keep-alive */ if (flags.keepalive || request->flags.pinned) { if (flags.proxying) { - httpHeaderPutStr(hdr_out, HDR_PROXY_CONNECTION, "keep-alive"); + httpHeaderPutString(hdr_out, HDR_PROXY_CONNECTION, stringDictGet(STR_KEEPALIVE)); } else { - httpHeaderPutStr(hdr_out, HDR_CONNECTION, "keep-alive"); + httpHeaderPutString(hdr_out, HDR_CONNECTION, stringDictGet(STR_KEEPALIVE)); } } /* append Front-End-Https */ Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.80.2.1.4.6 retrieving revision 1.80.2.1.4.7 diff -u -r1.80.2.1.4.6 -r1.80.2.1.4.7 --- squid/src/main.c 5 Jan 2008 09:42:40 -0000 1.80.2.1.4.6 +++ squid/src/main.c 21 Jan 2008 03:50:24 -0000 1.80.2.1.4.7 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.80.2.1.4.6 2008/01/05 09:42:40 adri Exp $ + * $Id: main.c,v 1.80.2.1.4.7 2008/01/21 03:50:24 adri Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -726,6 +726,7 @@ StringMapSetup(); memStringInit(); buf_init(); + stringDictInit(); getCurrentTime(); squid_start = current_time; Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.146.2.4.4.40 retrieving revision 1.146.2.4.4.41 diff -u -r1.146.2.4.4.40 -r1.146.2.4.4.41 --- squid/src/protos.h 20 Jan 2008 10:26:05 -0000 1.146.2.4.4.40 +++ squid/src/protos.h 21 Jan 2008 03:50:25 -0000 1.146.2.4.4.41 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.146.2.4.4.40 2008/01/20 10:26:05 adri Exp $ + * $Id: protos.h,v 1.146.2.4.4.41 2008/01/21 03:50:25 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1444,6 +1444,8 @@ /* String.c */ extern void stringStatsInit(void); - +extern void stringDictInit(void); +extern void stringDictAdd(int id, const char *str); +extern String stringDictGet(int id); #endif /* SQUID_PROTOS_H */