r4229 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Sep 4 12:53:52 CEST 2009


Author: phk
Date: 2009-09-04 12:53:51 +0200 (Fri, 04 Sep 2009)
New Revision: 4229

Modified:
   trunk/varnish-cache/bin/varnishd/stevedore.c
Log:
Factor the actual initialization of an object into a separate function.



Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2009-09-04 10:08:23 UTC (rev 4228)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2009-09-04 10:53:51 UTC (rev 4229)
@@ -87,6 +87,28 @@
 
 /*********************************************************************/
 
+static void
+STV_InitObj(struct sess *sp, struct object *o, unsigned wsl)
+{
+
+	memset(o, 0, sizeof *o);
+	o->magic = OBJECT_MAGIC;
+
+	WS_Init(o->ws_o, "obj", (o + 1), wsl);
+	WS_Assert(o->ws_o);
+
+	http_Setup(o->http, o->ws_o);
+	o->http->magic = HTTP_MAGIC;
+	o->refcnt = 1;
+	o->grace = NAN;
+	o->entered = NAN;
+	VTAILQ_INIT(&o->store);
+	VTAILQ_INIT(&o->esibits);
+	sp->wrk->stats.n_object++;
+}
+
+/*********************************************************************/
+
 struct object *
 STV_NewObject(struct sess *sp, unsigned l, double ttl)
 {
@@ -102,31 +124,19 @@
 	if (!sp->wrk->cacheable) {
 		o = malloc(sizeof *o + l);
 		XXXAN(o);
-	} else {
-		st = STV_alloc(sp, sizeof *o + l);
-		XXXAN(st);
-		xxxassert(st->space >= (sizeof *o + l));
+		STV_InitObj(sp, o, l);
+		return (o);
+	} 
+	st = STV_alloc(sp, sizeof *o + l);
+	XXXAN(st);
+	xxxassert(st->space >= (sizeof *o + l));
 
-		st->len = st->space;
-		l = st->space - sizeof *o;
+	st->len = st->space;
 
-		o = (void *)st->ptr; /* XXX: align ? */
-	}
-	memset(o, 0, sizeof *o);
+	o = (void *)st->ptr; /* XXX: align ? */
+
+	STV_InitObj(sp, o, st->space - sizeof *o);
 	o->objstore = st;
-	o->magic = OBJECT_MAGIC;
-
-	WS_Init(o->ws_o, "obj", (o + 1), l);
-	WS_Assert(o->ws_o);
-
-	http_Setup(o->http, o->ws_o);
-	o->http->magic = HTTP_MAGIC;
-	o->refcnt = 1;
-	o->grace = NAN;
-	o->entered = NAN;
-	VTAILQ_INIT(&o->store);
-	VTAILQ_INIT(&o->esibits);
-	sp->wrk->stats.n_object++;
 	return (o);
 }
 



More information about the varnish-commit mailing list