[master] 6567393d1 Simplify HSH_Lookup 2/N

Poul-Henning Kamp phk at FreeBSD.org
Tue Dec 4 23:47:08 UTC 2018


commit 6567393d1396738e32fc93a5fa2905d1ed2fef55
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Dec 4 22:02:05 2018 +0000

    Simplify HSH_Lookup 2/N
    
    Refactor the hit-cases
    
    Inspired by:    #2856

diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 55d1a8de9..7f9e6db78 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -452,46 +452,31 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 		}
 	}
 
+	if (oc != NULL && oc->flags & OC_F_HFP) {
+		xid = ObjGetXID(wrk, oc);
+		dttl = EXP_Dttl(req, oc);
+		AN(hsh_deref_objhead_unlock(wrk, &oh));
+		wrk->stats->cache_hitpass++;
+		VSLb(req->vsl, SLT_HitPass, "%u %.6f", xid, dttl);
+		return (HSH_HITPASS);
+	}
+
 	if (oc != NULL) {
-		if (oc->flags & OC_F_HFP) {
-			xid = ObjGetXID(wrk, oc);
-			dttl = EXP_Dttl(req, oc);
-			oc = NULL;
-			retval = HSH_HITPASS;
-		} else if (oc->flags & OC_F_HFM) {
+		*ocp = oc;
+		oc->refcnt++;
+		if (oc->flags & OC_F_HFM) {
 			xid = ObjGetXID(wrk, oc);
 			dttl = EXP_Dttl(req, oc);
 			*bocp = hsh_insert_busyobj(wrk, oh);
-			oc->refcnt++;
-			retval = HSH_HITMISS;
-		} else {
-			oc->refcnt++;
-			if (oc->hits < LONG_MAX)
-				oc->hits++;
-			retval = HSH_HIT;
-		}
-		*ocp = oc;
-		if (*bocp == NULL)
-			AN(hsh_deref_objhead_unlock(wrk, &oh));
-		else
 			Lck_Unlock(&oh->mtx);
-
-		switch (retval) {
-		case HSH_HITPASS:
-			wrk->stats->cache_hitpass++;
-			VSLb(req->vsl, SLT_HitPass, "%u %.6f", xid, dttl);
-			break;
-		case HSH_HITMISS:
 			wrk->stats->cache_hitmiss++;
 			VSLb(req->vsl, SLT_HitMiss, "%u %.6f", xid, dttl);
-			break;
-		case HSH_HIT:
-			break;
-		default:
-			INCOMPL();
-		}
-
-		return (retval);
+			return (HSH_HITMISS);
+		} 
+		if (oc->hits < LONG_MAX)
+			oc->hits++;
+		AN(hsh_deref_objhead_unlock(wrk, &oh));
+		return (HSH_HIT);
 	}
 
 	if (exp_oc != NULL && exp_oc->flags & OC_F_HFM) {
@@ -499,6 +484,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 		 * expired HFM ("grace/keep HFM")
 		 *
 		 * XXX should HFM objects actually have grace/keep ?
+		 * XXX also:  why isn't *ocp = exp_oc ?
 		 */
 		xid = ObjGetXID(wrk, exp_oc);
 		dttl = EXP_Dttl(req, exp_oc);


More information about the varnish-commit mailing list