From e0ba5089922f0827ae4115d5f94e4227628de2ff Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 11 Apr 2006 02:39:55 +0000 Subject: Store URLs explicitly in URL database for faster access. Iteration callbacks now passed url_data struct to remove need to look up svn path=/trunk/netsurf/; revision=2522 --- riscos/global_history.c | 52 ++++++++++++++++++++++++++----------------------- riscos/url_complete.c | 34 +++++++------------------------- 2 files changed, 35 insertions(+), 51 deletions(-) (limited to 'riscos') diff --git a/riscos/global_history.c b/riscos/global_history.c index 984df358c..a15d4431d 100644 --- a/riscos/global_history.c +++ b/riscos/global_history.c @@ -50,7 +50,8 @@ static void ro_gui_global_history_initialise_nodes(void); static void ro_gui_global_history_initialise_node(const char *title, time_t base, int days_back); static struct node *ro_gui_global_history_find(const char *url); -static bool global_history_iterate_callback(const char *url); +static bool global_history_add_internal(const char *url, + const struct url_data *data); /* The history window, toolbar and plot origins */ static wimp_w global_history_window; @@ -119,23 +120,10 @@ void ro_gui_global_history_initialise(void) } global_history_init = true; - urldb_iterate_entries(global_history_iterate_callback); + urldb_iterate_entries(global_history_add_internal); global_history_init = false; } -/** - * Callback for urldb_iterate_entries - * - * \param url The URL - * \return true to continue iteration, false otherwise - */ -bool global_history_iterate_callback(const char *url) -{ - global_history_add(url); - - return true; -} - /** * Initialises the base nodes */ @@ -267,19 +255,33 @@ int ro_gui_global_history_help(int x, int y) */ void global_history_add(const char *url) { - int i, j; const struct url_data *data; + + data = urldb_get_url_data(url); + if (!data) + return; + + global_history_add_internal(url, data); +} + +/** + * Internal routine to actually perform global history addition + * + * \param url The URL to add + * \param data URL data associated with URL + * \return true (for urldb_iterate_entries) + */ +bool global_history_add_internal(const char *url, + const struct url_data *data) +{ + int i, j; struct node *parent = NULL; struct node *link; struct node *node; bool before = false; int visit_date; - assert(url); - - data = urldb_get_url_data(url); - if (!data) - return; + assert(url && data); visit_date = data->last_visit; @@ -309,7 +311,7 @@ void global_history_add(const char *url) /* the entry is too old to care about */ if (!parent) - return; + return true; /* find any previous occurance */ if (!global_history_init) { @@ -326,7 +328,7 @@ void global_history_add(const char *url) node, false, true); /* ro_gui_tree_scroll_visible(hotlist_tree, &node->data); -*/ return; +*/ return true; } } @@ -339,6 +341,8 @@ void global_history_add(const char *url) tree_handle_node_changed(global_history_tree, node, true, false); } + + return true; } /** @@ -359,7 +363,7 @@ struct node *ro_gui_global_history_find(const char *url) node; node = node->next) { element = tree_find_element(node, TREE_ELEMENT_URL); - if ((element) && !strcmp(url, element->text)) + if ((element) && (url == element->text)) return node; } } diff --git a/riscos/url_complete.c b/riscos/url_complete.c index c31e0150d..1a179f21e 100644 --- a/riscos/url_complete.c +++ b/riscos/url_complete.c @@ -27,7 +27,7 @@ #define MAXIMUM_VISIBLE_LINES 7 -static char **url_complete_matches = NULL; +static const char **url_complete_matches = NULL; static int url_complete_matches_allocated = 0; static int url_complete_matches_available = 0; static char *url_complete_matched_string = NULL; @@ -38,7 +38,7 @@ static bool url_complete_matches_reset = false; static char *url_complete_original_url = NULL; static bool url_complete_memory_exhausted = false; -static char *url_complete_redraw[MAXIMUM_VISIBLE_LINES]; +static const char *url_complete_redraw[MAXIMUM_VISIBLE_LINES]; static char url_complete_icon_null[] = "\0"; static char url_complete_icon_sprite[12]; static wimp_icon url_complete_icon; @@ -160,14 +160,7 @@ bool ro_gui_url_complete_keypress(struct gui_window *g, int key) free(url_complete_matched_string); url_complete_matched_string = match_url; url_complete_original_url = NULL; - if (url_complete_matches) { - for (; url_complete_matches_available > 0; - url_complete_matches_available--) - free(url_complete_matches[ - url_complete_matches_available - 1]); - } else { - url_complete_matches_available = 0; - } + url_complete_matches_available = 0; url_complete_matches_selection = -1; url_complete_keypress_selection = -1; @@ -338,17 +331,16 @@ bool ro_gui_url_complete_keypress(struct gui_window *g, int key) */ bool url_complete_callback(const char *url) { - char **array_extend; - char *temp; + const char **array_extend; url_complete_matches_available++; if (url_complete_matches_available > url_complete_matches_allocated) { - array_extend = (char **)realloc(url_complete_matches, + array_extend = (const char **)realloc(url_complete_matches, (url_complete_matches_allocated + 64) * - sizeof(struct url_content *)); + sizeof(char *)); if (!array_extend) { url_complete_memory_exhausted = true; return false; @@ -357,13 +349,7 @@ bool url_complete_callback(const char *url) url_complete_matches_allocated += 64; } - temp = strdup(url); - if (!temp) { - url_complete_memory_exhausted = true; - return false; - } - - url_complete_matches[url_complete_matches_available - 1] = temp; + url_complete_matches[url_complete_matches_available - 1] = url; return true; } @@ -496,12 +482,6 @@ bool ro_gui_url_complete_close(struct gui_window *g, wimp_i i) currently_open = ((url_complete_parent) && (url_complete_matches_available > 0)); - if (url_complete_matches) { - for (; url_complete_matches_available > 0; - url_complete_matches_available--) - free(url_complete_matches[ - url_complete_matches_available - 1]); - } free(url_complete_matches); free(url_complete_matched_string); free(url_complete_original_url); -- cgit v1.2.3