From e68f319778277b34a4ade12a4c003b81c1b6c5a0 Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Mon, 2 Jan 2006 23:03:07 +0000 Subject: [project @ 2006-01-02 23:03:07 by rjw] Quickly match repeated hostname calls. svn path=/import/netsurf/; revision=1968 --- content/url_store.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'content/url_store.c') diff --git a/content/url_store.c b/content/url_store.c index 451027377..066607671 100644 --- a/content/url_store.c +++ b/content/url_store.c @@ -36,6 +36,7 @@ static struct hostname_data *url_store_match_hostname(const char *url, struct hostname_data *previous); static char *url_store_match_scheme = NULL; +static struct hostname_data *last_hostname_found = NULL; /** * Returns the hostname data for the specified URL. If no hostname @@ -49,26 +50,35 @@ struct hostname_data *url_store_find_hostname(const char *url) struct hostname_data *search; struct hostname_data *result; url_func_result res; - char *hostname; + char *hostname = NULL; int hostname_length; int compare; int fast_exit_counter = ITERATIONS_BEFORE_TEST; assert(url); + /* try to match the last hostname for http:// */ + if ((last_hostname_found) && + (!strncmp("http://", url, 7)) && + (!strncmp(last_hostname_found->hostname, url + 7, + last_hostname_found->hostname_length))) { + return last_hostname_found; + } + + /* no match found, fallback */ res = url_host(url, &hostname); switch (res) { - case URL_FUNC_OK: - break; - case URL_FUNC_NOMEM: - return NULL; - case URL_FUNC_FAILED: - hostname = strdup("file:/"); /* for 'file:/' */ - if (!hostname) + case URL_FUNC_OK: + break; + case URL_FUNC_NOMEM: return NULL; - break; - default: - assert(0); + case URL_FUNC_FAILED: + hostname = strdup("file:/"); /* for 'file:/' */ + if (!hostname) + return NULL; + break; + default: + assert(0); } hostname_length = strlen(hostname); @@ -79,6 +89,7 @@ struct hostname_data *url_store_find_hostname(const char *url) compare = strcmp(hostname, search->hostname); if (compare == 0) { free(hostname); + last_hostname_found = search; return search; } else if (compare < 0) break; @@ -99,6 +110,7 @@ struct hostname_data *url_store_find_hostname(const char *url) result->url = 0; result->previous = 0; result->next = 0; + last_hostname_found = result; /* simple case: no current hostnames */ if (!url_store_hostnames) { -- cgit v1.2.3