From 1537981da5415302438489617422b0e3f9b4c6e9 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 10 Feb 2010 23:37:06 +0000 Subject: cache the status text to reduce teh number of window status update calls to teh frontend svn path=/trunk/netsurf/; revision=9965 --- desktop/browser.c | 34 +++++++++++++++++++++++++++++++++- desktop/browser.h | 6 ++++++ 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'desktop') diff --git a/desktop/browser.c b/desktop/browser.c index 40eef67ef..2a3d8d7ea 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -196,6 +196,9 @@ void browser_window_initialise_common(struct browser_window *bw, bw->reformat_pending = false; bw->drag_type = DRAGGING_NONE; bw->scale = (float) option_scale / 100.0; + + bw->status_text = NULL; + bw->status_text_len = 0; } @@ -906,9 +909,34 @@ void browser_window_reload(struct browser_window *bw, bool all) void browser_window_set_status(struct browser_window *bw, const char *text) { + int text_len; + /* find topmost window */ while (bw->parent) bw = bw->parent; - gui_window_set_status(bw->window, text); + + if ((bw->status_text != NULL) && + (strcmp(text, bw->status_text) == 0)) { + /* status text is unchanged */ + bw->status_match++; + return; + } + + /* status text is changed */ + + text_len = strlen(text); + + if ((bw->status_text == NULL) || (bw->status_text_len < text_len)) { + /* no current string allocation or it is not long enough */ + free(bw->status_text); + bw->status_text = strdup(text); + bw->status_text_len = text_len; + } else { + /* current allocation has enough space */ + memcpy(bw->status_text, text, text_len + 1); + } + + bw->status_miss++; + gui_window_set_status(bw->window, text); } @@ -1006,6 +1034,10 @@ void browser_window_destroy_internal(struct browser_window *bw) free(bw->name); free(bw->frag_id); + free(bw->status_text); + bw->status_text = NULL; + LOG(("Status text cache match:miss %d:%d", + bw->status_match, bw->status_miss)); } diff --git a/desktop/browser.h b/desktop/browser.h index ee777c832..9743054e7 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -175,6 +175,12 @@ struct browser_window { struct search_context *search_context; struct form_control *visible_select_menu; + + /** cache of the currently displayed status text. */ + char *status_text; + int status_text_len; + int status_match; + int status_miss; }; -- cgit v1.2.3