dovecot-2.2: lib-http: Track list of hosts using a linked list a...

dovecot at dovecot.org dovecot at dovecot.org
Tue Feb 26 13:03:42 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/4655adf5affc
changeset: 15972:4655adf5affc
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Feb 26 13:03:30 2013 +0200
description:
lib-http: Track list of hosts using a linked list also.
http_client_switch_ioloop() is done very often, and scanning a few entries
in a linked list is much faster than going through a hash table.

diffstat:

 src/lib-http/http-client-host.c    |   6 ++++++
 src/lib-http/http-client-private.h |   3 +++
 src/lib-http/http-client.c         |  13 +++----------
 3 files changed, 12 insertions(+), 10 deletions(-)

diffs (95 lines):

diff -r b90a89ca840f -r 4655adf5affc src/lib-http/http-client-host.c
--- a/src/lib-http/http-client-host.c	Tue Feb 26 11:30:11 2013 +0200
+++ b/src/lib-http/http-client-host.c	Tue Feb 26 13:03:30 2013 +0200
@@ -5,6 +5,7 @@
 #include "str.h"
 #include "hash.h"
 #include "array.h"
+#include "llist.h"
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
@@ -276,6 +277,7 @@
 
 		hostname = host->name;
 		hash_table_insert(client->hosts, hostname, host);
+		DLLIST_PREPEND(&client->hosts_list, host);
 
 		http_client_host_debug(host, "Host created");
 	}
@@ -367,9 +369,13 @@
 {
 	struct http_client_host *host = *_host;
 	struct http_client_host_port *hport;
+	const char *hostname = host->name;
 
 	http_client_host_debug(host, "Host destroy");
 
+	DLLIST_REMOVE(&host->client->hosts_list, host);
+	hash_table_remove(host->client->hosts, hostname);
+
 	if (host->dns_lookup != NULL)
 		dns_lookup_abort(&host->dns_lookup);
 
diff -r b90a89ca840f -r 4655adf5affc src/lib-http/http-client-private.h
--- a/src/lib-http/http-client-private.h	Tue Feb 26 11:30:11 2013 +0200
+++ b/src/lib-http/http-client-private.h	Tue Feb 26 13:03:30 2013 +0200
@@ -94,6 +94,8 @@
 };
 
 struct http_client_host {
+	struct http_client_host *prev, *next;
+
 	struct http_client *client;
 	char *name;
 
@@ -175,6 +177,7 @@
 	struct connection_list *conn_list;
 
 	HASH_TABLE_TYPE(http_client_host) hosts;
+	struct http_client_host *hosts_list;
 	HASH_TABLE_TYPE(http_client_peer) peers;
 	unsigned int pending_requests;
 };
diff -r b90a89ca840f -r 4655adf5affc src/lib-http/http-client.c
--- a/src/lib-http/http-client.c	Tue Feb 26 11:30:11 2013 +0200
+++ b/src/lib-http/http-client.c	Tue Feb 26 13:03:30 2013 +0200
@@ -104,7 +104,6 @@
 {
 	struct http_client *client = *_client;
 	struct hash_iterate_context *iter;
-	const char *hostname;
 	struct http_client_host *host;
 	const struct http_client_peer_addr *addr;
 	struct http_client_peer *peer;
@@ -118,11 +117,10 @@
 	hash_table_destroy(&client->peers);
 
 	/* free hosts */
-	iter = hash_table_iterate_init(client->hosts);
-	while (hash_table_iterate(iter, client->hosts, &hostname, &host)) {
+	while (client->hosts_list != NULL) {
+		host = client->hosts_list;
 		http_client_host_free(&host);
 	}
-	hash_table_iterate_deinit(&iter);
 	hash_table_destroy(&client->hosts);
 
 	connection_list_deinit(&client->conn_list);
@@ -147,15 +145,10 @@
 
 	/* move dns lookups */
 	if (client->set.dns_client_socket_path != '\0') {
-		struct hash_iterate_context *iter;
 		struct http_client_host *host;
-		const char *hostname;
 	
-		iter = hash_table_iterate_init(client->hosts);
-		while (hash_table_iterate(iter, client->hosts, &hostname, &host)) {
+		for (host = client->hosts_list; host != NULL; host = host->next)
 			http_client_host_switch_ioloop(host);
-		}
-		hash_table_iterate_deinit(&iter);
 	}
 }
 


More information about the dovecot-cvs mailing list