[6.0] a79e90ffe Simplify HSH_Lookup 1/N
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Feb 8 13:13:10 UTC 2019
commit a79e90ffe12e4656f125344d0dcfaf190a7ede26
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Dec 4 21:54:16 2018 +0000
Simplify HSH_Lookup 1/N
Move successful loop termination out of the loop.
Inspired by: #2856
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index cfda2bb9c..15c8fe8bb 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -439,51 +439,11 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
}
if (EXP_Ttl(req, oc) > req->t_req) {
- /* If still valid, use it */
assert(oh->refcnt > 1);
assert(oc->objhead == oh);
- 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) {
- 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);
+ break;
}
+
if (EXP_Ttl(NULL, oc) < req->t_req && /* ignore req.ttl */
oc->t_origin > exp_t_origin) {
/* record the newest object */
@@ -492,6 +452,48 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
}
}
+ 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) {
+ 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);
+ }
+
if (exp_oc != NULL && exp_oc->flags & OC_F_HFM) {
/*
* expired HFM ("grace/keep HFM")
More information about the varnish-commit
mailing list