From: phk Date: Tue, 25 Nov 2008 10:20:16 +0000 (+0000) Subject: Isolate some hash-string building nastyness in cache_hash.c X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f88e6101e693f99a99e5cef0bda795873132f0a7;p=varnish Isolate some hash-string building nastyness in cache_hash.c git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3434 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index ffcdc6f0..f9995496 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 8596c61b..d299bfd7 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -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) { diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 61ba299a..7bf5b286 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -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); } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/hash_slinger.h b/varnish-cache/bin/varnishd/hash_slinger.h index 753788b7..91ff69b6 100644 --- a/varnish-cache/bin/varnishd/hash_slinger.h +++ b/varnish-cache/bin/varnishd/hash_slinger.h @@ -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