summaryrefslogtreecommitdiff
path: root/backends/markup-tree.c
diff options
context:
space:
mode:
authorMark McLoughlin <mark@skynet.ie>2003-03-13 20:24:57 +0000
committerMark McLoughlin <markmc@src.gnome.org>2003-03-13 20:24:57 +0000
commite4591a0515a9099b6dbb40544b2316ef30bbd2bd (patch)
tree286e3ffedb3bd1e6c99e339e3de5e8e923cebcd6 /backends/markup-tree.c
parentc1fb45668f6024c8d5c82b5f11db6eaf8bceb352 (diff)
downloadgconf-e4591a0515a9099b6dbb40544b2316ef30bbd2bd.tar.gz
Basically the same patch as the previous one .. but for the markup
2003-03-14 Mark McLoughlin <mark@skynet.ie> Basically the same patch as the previous one .. but for the markup backend. * backends/markup-backend.c: (resolve_address): update. (clear_cache): use markup_tree_rebuild() instead of re-creating the tree. (ms_new): remove the read_only arg and s/markup_tree_new/ markup_tree_get/ (ms_destroy): s/markup_tree_free/markup_tree_unref/ * backends/markup-tree.[ch]: (markup_tree_get), (markup_tree_unref): rename these from new()/free() and share caches for sources with the same root directory. (markup_tree_rebuild): impl. (markup_dir_needs_sync): we don't keep the read_only flag per-tree anymore so don't check it here.
Diffstat (limited to 'backends/markup-tree.c')
-rw-r--r--backends/markup-tree.c64
1 files changed, 50 insertions, 14 deletions
diff --git a/backends/markup-tree.c b/backends/markup-tree.c
index 98209e10..81c291f3 100644
--- a/backends/markup-tree.c
+++ b/backends/markup-tree.c
@@ -89,37 +89,80 @@ struct _MarkupTree
MarkupDir *root;
- guint read_only : 1;
+ guint refcount;
};
+static GHashTable *trees_by_root_dir = NULL;
+
MarkupTree*
-markup_tree_new (const char *root_dir,
+markup_tree_get (const char *root_dir,
guint dir_mode,
- guint file_mode,
- gboolean read_only)
+ guint file_mode)
{
- MarkupTree *tree;
+ MarkupTree *tree = NULL;
+
+ if (trees_by_root_dir == NULL)
+ trees_by_root_dir = g_hash_table_new (g_str_hash, g_str_equal);
+ else
+ tree = g_hash_table_lookup (trees_by_root_dir, root_dir);
+
+ if (tree != NULL)
+ {
+ tree->refcount += 1;
+ return tree;
+ }
tree = g_new0 (MarkupTree, 1);
tree->dirname = g_strdup (root_dir);
tree->dir_mode = dir_mode;
tree->file_mode = file_mode;
- tree->read_only = read_only;
tree->root = markup_dir_new (tree, NULL, "/");
+
+ tree->refcount = 1;
+
+ g_hash_table_insert (trees_by_root_dir, tree->dirname, tree);
return tree;
}
void
-markup_tree_free (MarkupTree *tree)
+markup_tree_unref (MarkupTree *tree)
{
+ g_return_if_fail (tree != NULL);
+ g_return_if_fail (tree->refcount > 0);
+
+ if (tree->refcount > 1)
+ {
+ tree->refcount -= 1;
+ return;
+ }
+
+ g_hash_table_remove (trees_by_root_dir, tree->dirname);
+ if (g_hash_table_size (trees_by_root_dir) == 0)
+ {
+ g_hash_table_destroy (trees_by_root_dir);
+ trees_by_root_dir = NULL;
+ }
+
+ markup_dir_free (tree->root);
+ tree->root = NULL;
+
g_free (tree->dirname);
g_free (tree);
}
+void
+markup_tree_rebuild (MarkupTree *tree)
+{
+ g_return_if_fail (markup_dir_needs_sync (tree->root));
+
+ markup_dir_free (tree->root);
+ tree->root = markup_dir_new (tree, NULL, "/");
+}
+
struct _MarkupDir
{
MarkupTree *tree;
@@ -585,13 +628,6 @@ markup_dir_get_name (MarkupDir *dir)
static gboolean
markup_dir_needs_sync (MarkupDir *dir)
{
- /* Never write to read-only tree
- * (it shouldn't get marked dirty, but this
- * is here as a safeguard)
- */
- if (dir->tree->read_only)
- return FALSE;
-
return dir->entries_need_save || dir->some_subdir_needs_sync;
}