Mailing List Archive

r3434 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2008-11-25 11:20:16 +0100 (Tue, 25 Nov 2008)
New Revision: 3434

Modified:
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/cache_hash.c
trunk/varnish-cache/bin/varnishd/cache_vrt.c
trunk/varnish-cache/bin/varnishd/hash_slinger.h
Log:
Isolate some hash-string building nastyness in cache_hash.c



Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-11-25 08:37:34 UTC (rev 3433)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-11-25 10:20:16 UTC (rev 3434)
@@ -586,28 +586,12 @@
cnt_lookup(struct sess *sp)
{
struct object *o;
- char *p;
- uintptr_t u;

CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);

if (sp->obj == NULL) {
-
- /* Allocate the pointers we need, align properly. */
- sp->lhashptr = 1; /* space for NUL */
- sp->ihashptr = 0;
- sp->nhashptr = sp->vcl->nhashcount * 2;
- p = WS_Alloc(sp->http->ws,
- sizeof(const char *) * (sp->nhashptr + 1));
- XXXAN(p);
- /* Align pointer properly (?) */
- u = (uintptr_t)p;
- u &= sizeof(const char *) - 1;
- if (u)
- p += sizeof(const char *) - u;
- sp->hashptr = (void*)p;
-
+ HSH_Prepare(sp, sp->vcl->nhashcount);
VCL_hash_method(sp);
assert(sp->handling == VCL_RET_HASH);
}

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-11-25 08:37:34 UTC (rev 3433)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-11-25 10:20:16 UTC (rev 3434)
@@ -201,6 +201,48 @@
assert(b <= oh->hash + oh->hashlen);
}

+void
+HSH_Prepare(struct sess *sp, unsigned nhashcount)
+{
+ char *p;
+ unsigned u;
+
+ /* Allocate the pointers we need, align properly. */
+ sp->lhashptr = 1; /* space for NUL */
+ sp->ihashptr = 0;
+ sp->nhashptr = nhashcount * 2;
+ p = WS_Alloc(sp->http->ws, sizeof(const char *) * (sp->nhashptr + 1));
+ XXXAN(p);
+ /* Align pointer properly (?) */
+ u = (uintptr_t)p;
+ u &= sizeof(const char *) - 1;
+ if (u)
+ p += sizeof(const char *) - u;
+ sp->hashptr = (void*)p;
+}
+
+void
+HSH_AddString(struct sess *sp, const char *str)
+{
+ int l;
+
+ if (str == NULL)
+ str = "";
+ l = strlen(str);
+
+ /*
+ * XXX: handle this by bouncing sp->vcl->nhashcount when it fails
+ * XXX: and dispose of this request either by reallocating the
+ * XXX: hashptr (if possible) or restarting/error the request
+ */
+ xxxassert(sp->ihashptr < sp->nhashptr);
+
+ sp->hashptr[sp->ihashptr] = str;
+ sp->hashptr[sp->ihashptr + 1] = str + l;
+ sp->ihashptr += 2;
+ sp->lhashptr += l + 1;
+}
+
struct object *
HSH_Lookup(struct sess *sp)
{

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-11-25 08:37:34 UTC (rev 3433)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-11-25 10:20:16 UTC (rev 3434)
@@ -585,23 +585,8 @@
void
VRT_l_req_hash(struct sess *sp, const char *str)
{
- int l;

- if (str == NULL)
- str = "";
- l = strlen(str);
-
- /*
- * XXX: handle this by bouncing sp->vcl->nhashcount when it fails
- * XXX: and dispose of this request either by reallocating the
- * XXX: hashptr (if possible) or restarting/error the request
- */
- xxxassert(sp->ihashptr < sp->nhashptr);
-
- sp->hashptr[sp->ihashptr] = str;
- sp->hashptr[sp->ihashptr + 1] = str + l;
- sp->ihashptr += 2;
- sp->lhashptr += l + 1;
+ HSH_AddString(sp, str);
}

/*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2008-11-25 08:37:34 UTC (rev 3433)
+++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2008-11-25 10:20:16 UTC (rev 3434)
@@ -59,6 +59,8 @@
void HSH_Deref(struct object *o);
double HSH_Grace(double g);
void HSH_Init(void);
+void HSH_AddString(struct sess *sp, const char *str);
+void HSH_Prepare(struct sess *sp, unsigned hashcount);


#ifdef VARNISH_CACHE_CHILD