Commit d94204a3 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Isolate some hash-string building nastyness in cache_hash.c



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3434 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 1123e733
......@@ -586,28 +586,12 @@ static int
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);
}
......
......@@ -201,6 +201,48 @@ HSH_Copy(const struct sess *sp, struct objhead *oh)
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)
{
......
......@@ -585,23 +585,8 @@ VRT_r_server_port(struct sess *sp)
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);
}
/*--------------------------------------------------------------------*/
......
......@@ -59,6 +59,8 @@ void HSH_Ref(struct object *o);
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment