From 2add69b7f08f19ae2687276ebafcf6989915aa69 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 24 Nov 2012 19:54:20 +0100 Subject: cache GLists corresponding to symbol lists --- symbols.cpp | 8 ++++---- symbols.h | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/symbols.cpp b/symbols.cpp index 8e81354..c05d153 100644 --- a/symbols.cpp +++ b/symbols.cpp @@ -51,10 +51,10 @@ SymbolList::lookup(const gchar *name, const gchar *prefix, bool case_sensitive) GList * SymbolList::get_glist(void) { - GList *list = NULL; - - while (size--) - list = g_list_prepend(list, (gchar *)entries[size].name); + if (!list) { + for (gint i = size; i; i--) + list = g_list_prepend(list, (gchar *)entries[i-1].name); + } return list; } diff --git a/symbols.h b/symbols.h index a603b3b..1c48ddf 100644 --- a/symbols.h +++ b/symbols.h @@ -14,9 +14,16 @@ private: const Entry *entries; gint size; + /* for auto-completions */ + GList *list; + public: SymbolList(const Entry *_entries = NULL, gint _size = 0) - : entries(_entries), size(_size) {} + : entries(_entries), size(_size), list(NULL) {} + ~SymbolList() + { + g_list_free(list); + } gint lookup(const gchar *name, const gchar *prefix = "", bool case_sensitive = false); -- cgit v1.2.3