[master] 7e2475da4 vcp: polish

Nils Goroll nils.goroll at uplex.de
Thu Apr 10 06:47:06 UTC 2025


commit 7e2475da44d1f8165dfe412702b7923857bdb99b
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Thu Apr 10 08:42:11 2025 +0200

    vcp: polish
    
    A recent polish of VCP_Ref() in a80160a0c5e5390ae9c81d790b157b5a7c05eb88 made me
    notice that VRBT_FIND + optional VRBT_INSERT is just duplicating tree traversal
    for the insert case.
    
    Only use VRBT_INSERT - it already returns an existing element and is only
    marginally less efficient (the comparison function dominates). Using an
    additional VRBT_FIND would make sense if we did not create the element to be
    inserted upfront.

diff --git a/bin/varnishd/cache/cache_conn_pool.c b/bin/varnishd/cache/cache_conn_pool.c
index d947cbfcd..fafb41b96 100644
--- a/bin/varnishd/cache/cache_conn_pool.c
+++ b/bin/varnishd/cache/cache_conn_pool.c
@@ -110,7 +110,6 @@ static struct lock dead_pools_mtx;
 VRBT_HEAD(vrb, conn_pool);
 VRBT_GENERATE_REMOVE_COLOR(vrb, conn_pool, entry, static)
 VRBT_GENERATE_REMOVE(vrb, conn_pool, entry, static)
-VRBT_GENERATE_FIND(vrb, conn_pool, entry, vcp_cmp, static)
 VRBT_GENERATE_INSERT_COLOR(vrb, conn_pool, entry, static)
 VRBT_GENERATE_INSERT_FINISH(vrb, conn_pool, entry, static)
 VRBT_GENERATE_INSERT(vrb, conn_pool, entry, vcp_cmp, static)
@@ -813,9 +812,8 @@ VCP_Ref(const struct vrt_endpoint *vep, const char *ident)
 	VTAILQ_INIT(&cp->connlist);
 
 	Lck_Lock(&conn_pools_mtx);
-	cp2 = VRBT_FIND(vrb, &conn_pools, cp);
+	cp2 = VRBT_INSERT(vrb, &conn_pools, cp);
 	if (cp2 == NULL) {
-		AZ(VRBT_INSERT(vrb, &conn_pools, cp));
 		Lck_Unlock(&conn_pools_mtx);
 		return (cp);
 	}


More information about the varnish-commit mailing list