summaryrefslogtreecommitdiff
path: root/riscos/wimp_event.c
diff options
context:
space:
mode:
authorAdrian Lees <adrian@aemulor.com>2006-02-01 17:34:36 +0000
committerAdrian Lees <adrian@aemulor.com>2006-02-01 17:34:36 +0000
commit158b6e1835be9558aad0c4201d7f29d0be12aec2 (patch)
treeba3b6e83e1a908ec7912da5f64ec9869eb3180b8 /riscos/wimp_event.c
parent2e7b32ea5a8e6ec72886466e1e6421f4e82d33d3 (diff)
downloadnetsurf-158b6e1835be9558aad0c4201d7f29d0be12aec2.tar.gz
netsurf-158b6e1835be9558aad0c4201d7f29d0be12aec2.tar.bz2
[project @ 2006-02-01 17:34:36 by adrianl]
Use hash table for faster access to event_windows svn path=/import/netsurf/; revision=2051
Diffstat (limited to 'riscos/wimp_event.c')
-rw-r--r--riscos/wimp_event.c60
1 files changed, 43 insertions, 17 deletions
diff --git a/riscos/wimp_event.c b/riscos/wimp_event.c
index f85c48add..c0f9fbe1e 100644
--- a/riscos/wimp_event.c
+++ b/riscos/wimp_event.c
@@ -23,6 +23,9 @@
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
+#define WIN_HASH_SIZE 32
+#define WIN_HASH(w) (((unsigned)(w) >> 5) % WIN_HASH_SIZE)
+
typedef enum {
EVENT_NUMERIC_FIELD,
EVENT_TEXT_FIELD,
@@ -89,8 +92,9 @@ static struct event_window *ro_gui_wimp_event_find_window(wimp_w w);
static struct icon_event *ro_gui_wimp_event_get_event(wimp_w w, wimp_i i,
event_type type);
static void ro_gui_wimp_event_prepare_menu(wimp_w w, struct icon_event *event);
+static struct event_window *ro_gui_wimp_event_remove_window(wimp_w w);
-static struct event_window *ro_gui_wimp_event_windows;
+static struct event_window *ro_gui_wimp_event_windows[WIN_HASH_SIZE];
/**
@@ -217,24 +221,12 @@ bool ro_gui_wimp_event_validate(wimp_w w) {
*/
void ro_gui_wimp_event_finalise(wimp_w w) {
struct event_window *window;
- struct event_window *link;
struct icon_event *event;
- window = ro_gui_wimp_event_find_window(w);
+ window = ro_gui_wimp_event_remove_window(w);
if (!window)
return;
- if (window == ro_gui_wimp_event_windows) {
- ro_gui_wimp_event_windows = window->next;
- } else {
- for (link = ro_gui_wimp_event_windows; link; link = link->next) {
- if (link->next == window) {
- link->next = window->next;
- break;
- }
- }
- }
-
while (window->first) {
event = window->first;
window->first = event->next;
@@ -967,6 +959,7 @@ bool ro_gui_wimp_event_register_menu_selection(wimp_w w,
*/
struct event_window *ro_gui_wimp_event_get_window(wimp_w w) {
struct event_window *window;
+ int h;
window = ro_gui_wimp_event_find_window(w);
if (window)
@@ -975,22 +968,55 @@ struct event_window *ro_gui_wimp_event_get_window(wimp_w w) {
window = calloc(1, sizeof(struct event_window));
if (!window)
return NULL;
+
+ h = WIN_HASH(w);
window->w = w;
- window->next = ro_gui_wimp_event_windows;
- ro_gui_wimp_event_windows = window;
+ window->next = ro_gui_wimp_event_windows[h];
+ ro_gui_wimp_event_windows[h] = window;
return window;
}
/**
+ * Removes the event data associated with a given handle from the hash tables,
+ * but does not delete it.
+ *
+ * \param w the window to be removed
+ * \return pointer to the event data or NULL if not found
+ */
+
+struct event_window *ro_gui_wimp_event_remove_window(wimp_w w) {
+ struct event_window **prev;
+ int h = WIN_HASH(w);
+
+ /* search hash chain for the window */
+ prev = &ro_gui_wimp_event_windows[h];
+ while (*prev) {
+ struct event_window *window = *prev;
+
+ if (window->w == w) {
+ /* remove from chain */
+ *prev = window->next;
+ return window;
+ }
+ prev = &window->next;
+ }
+
+ /* not found */
+ return NULL;
+}
+
+/**
* Find the event data associated with a given window handle
*
* \param w the window to find data for
*/
struct event_window *ro_gui_wimp_event_find_window(wimp_w w) {
struct event_window *window;
+ int h = WIN_HASH(w);
- for (window = ro_gui_wimp_event_windows; window; window = window->next) {
+ /* search hash chain for window */
+ for (window = ro_gui_wimp_event_windows[h]; window; window = window->next) {
if (window->w == w)
return window;
}