]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: use the tree to look up the server name in findserver()
authorWilly Tarreau <w@1wt.eu>
Thu, 10 Jul 2025 09:06:41 +0000 (11:06 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 15 Jul 2025 08:30:27 +0000 (10:30 +0200)
Let's just use the tree-based lookup instead of walking through the list.
This function is used to find duplicates in "track" statements and a few
such places, so it's important not to waste too much time on large setups.

include/haproxy/server.h
src/server.c

index e435f9a1f990759b73794605474b9632c88cf94b..eb6d5fde6e6b9a4924bbbc89cedb806a72450a89 100644 (file)
@@ -61,7 +61,7 @@ const char *srv_update_check_addr_port(struct server *s, const char *addr, const
 const char *srv_update_agent_addr_port(struct server *s, const char *addr, const char *port);
 struct server *server_find_by_id(struct proxy *bk, int id);
 struct server *server_find_by_id_unique(struct proxy *bk, int id, uint32_t rid);
-struct server *findserver(const struct proxy *px, const char *name);
+struct server *findserver(struct proxy *px, const char *name);
 struct server *server_find_by_name(struct proxy *bk, const char *name);
 struct server *server_find_by_name_unique(struct proxy *bk, const char *name, uint32_t rid);
 struct server *server_find_best_match(struct proxy *bk, char *name, int id, int *diff);
index 44e7c48586f527cc9843a0022704d64291ad65a7..7f3b818628fe71c834a69f16ddadd10d1ecd2f01 100644 (file)
@@ -4006,20 +4006,17 @@ struct server *server_find_by_id_unique(struct proxy *bk, int id, uint32_t rid)
  * This function returns the server with a matching name within selected proxy,
  * or NULL if not found.
  */
-
-struct server *findserver(const struct proxy *px, const char *name)
+struct server *findserver(struct proxy *px, const char *name)
 {
+       struct ebpt_node *node;
        struct server *cursrv;
 
        if (!px)
                return NULL;
 
-       for (cursrv = px->srv; cursrv; cursrv = cursrv->next) {
-               if (strcmp(cursrv->id, name) == 0)
-                       return cursrv;
-       }
-
-       return NULL;
+       node = ebis_lookup(&px->conf.used_server_name, name);
+       cursrv = node ? container_of(node, struct server, conf.name) : NULL;
+       return cursrv;
 }
 
 /* Returns a pointer to the first server matching either name <name>, or id