Permalink
Browse files

Avoid unnecessary hash table for global tag filenames

  • Loading branch information...
1 parent 6e46a7b commit 3f7b888b32a46683f8d67902df4c5d45ddb11a0e @ntrel ntrel committed Apr 26, 2012
Showing with 21 additions and 29 deletions.
  1. +6 −3 src/filetypes.c
  2. +1 −0 src/filetypesprivate.h
  3. +14 −26 src/symbols.c
View
@@ -1124,12 +1124,15 @@ static void filetype_free(gpointer data, G_GNUC_UNUSED gpointer user_data)
g_free(ft->ftdefcmds);
g_free(ft->execcmds);
g_free(ft->error_regex_string);
- if (ft->priv->error_regex)
- g_regex_unref(ft->priv->error_regex);
if (ft->icon)
g_object_unref(ft->icon);
-
g_strfreev(ft->pattern);
+
+ if (ft->priv->error_regex)
+ g_regex_unref(ft->priv->error_regex);
+ g_slist_foreach(ft->priv->tag_files, (GFunc) g_free, NULL);
+ g_slist_free(ft->priv->tag_files);
+
g_free(ft->priv);
g_free(ft);
}
@@ -34,6 +34,7 @@ typedef struct GeanyFiletypePrivate
gboolean custom;
gint symbol_list_sort_mode;
gboolean xml_indent_tags; /* XML tag autoindentation, for HTML and XML filetypes */
+ GSList *tag_files;
}
GeanyFiletypePrivate;
View
@@ -53,6 +53,7 @@
#include "ui_utils.h"
#include "editor.h"
#include "sciwrappers.h"
+#include "filetypesprivate.h"
const guint TM_GLOBAL_TYPE_MASK =
@@ -1810,15 +1811,12 @@ void symbols_show_load_tags_dialog(void)
}
-/* Fills a hash table with filetype keys that hold a linked list of filenames. */
-static GHashTable *get_tagfile_hash(const GSList *file_list)
+static void detect_tag_files(const GSList *file_list)
{
const GSList *node;
- GHashTable *hash = g_hash_table_new(NULL, NULL);
for (node = file_list; node != NULL; node = g_slist_next(node))
{
- GList *fnames;
gchar *fname = node->data;
gchar *utf8_fname = utils_get_utf8_from_locale(fname);
GeanyFiletype *ft = detect_global_tags_filetype(utf8_fname);
@@ -1827,21 +1825,17 @@ static GHashTable *get_tagfile_hash(const GSList *file_list)
if (FILETYPE_ID(ft) != GEANY_FILETYPES_NONE)
{
- fnames = g_hash_table_lookup(hash, ft); /* may be NULL */
- fnames = g_list_append(fnames, fname);
- g_hash_table_insert(hash, ft, fnames);
+ ft->priv->tag_files = g_slist_append(ft->priv->tag_files, fname);
}
else
geany_debug("Unknown filetype for file '%s'.", fname);
}
- return hash;
}
-static GHashTable *init_user_tags(void)
+static void init_user_tags(void)
{
GSList *file_list = NULL, *list = NULL;
- GHashTable *lang_hash;
gchar *dir;
dir = g_build_filename(app->configdir, "tags", NULL);
@@ -1857,21 +1851,17 @@ static GHashTable *init_user_tags(void)
g_free(dir);
file_list = g_slist_concat(file_list, list);
-
- lang_hash = get_tagfile_hash(file_list);
- /* don't need to delete list contents because they are now used for hash contents */
+ detect_tag_files(file_list);
+ /* don't need to delete list contents because they are stored in ft->priv->tag_files */
g_slist_free(file_list);
-
- return lang_hash;
}
static void load_user_tags(filetype_id ft_id)
{
static guchar *tags_loaded = NULL;
- static GHashTable *lang_hash = NULL;
- GList *fnames;
- const GList *node;
+ static gboolean init_tags = FALSE;
+ const GSList *node;
GeanyFiletype *ft = filetypes[ft_id];
g_return_if_fail(ft_id > 0);
@@ -1882,20 +1872,18 @@ static void load_user_tags(filetype_id ft_id)
return;
tags_loaded[ft_id] = TRUE; /* prevent reloading */
- if (lang_hash == NULL)
- lang_hash = init_user_tags();
-
- fnames = g_hash_table_lookup(lang_hash, ft);
+ if (!init_tags)
+ {
+ init_user_tags();
+ init_tags = TRUE;
+ }
- for (node = fnames; node != NULL; node = g_list_next(node))
+ for (node = ft->priv->tag_files; node != NULL; node = g_slist_next(node))
{
const gchar *fname = node->data;
symbols_load_global_tags(fname, ft);
}
- g_list_foreach(fnames, (GFunc) g_free, NULL);
- g_list_free(fnames);
- g_hash_table_remove(lang_hash, (gpointer) ft);
}

0 comments on commit 3f7b888

Please sign in to comment.