[gnome-builder] snippets: make snippet context creation lazy
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] snippets: make snippet context creation lazy
- Date: Wed, 24 Dec 2014 02:36:55 +0000 (UTC)
commit b60698dc933181645fd52ea2ec471277792ef60e
Author: Christian Hergert <christian hergert me>
Date: Tue Dec 23 18:36:48 2014 -0800
snippets: make snippet context creation lazy
Should save some memory, string allocations, and make startup faster.
src/snippets/gb-source-snippet-chunk.c | 43 +++++++++++++++++---------------
src/snippets/gb-source-snippet.c | 29 +++++++++++++++++---
2 files changed, 47 insertions(+), 25 deletions(-)
---
diff --git a/src/snippets/gb-source-snippet-chunk.c b/src/snippets/gb-source-snippet-chunk.c
index 4389ca5..5194908 100644
--- a/src/snippets/gb-source-snippet-chunk.c
+++ b/src/snippets/gb-source-snippet-chunk.c
@@ -100,31 +100,34 @@ gb_source_snippet_chunk_set_context (GbSourceSnippetChunk *chunk,
GbSourceSnippetChunkPrivate *priv;
g_return_if_fail (GB_IS_SOURCE_SNIPPET_CHUNK (chunk));
- g_return_if_fail (GB_IS_SOURCE_SNIPPET_CONTEXT (context));
+ g_return_if_fail (!context || GB_IS_SOURCE_SNIPPET_CONTEXT (context));
priv = chunk->priv;
- if (priv->context_changed_handler)
- {
- g_signal_handler_disconnect (priv->context,
- priv->context_changed_handler);
- priv->context_changed_handler = 0;
- }
-
- g_clear_object (&chunk->priv->context);
-
- if (context)
+ if (context != chunk->priv->context)
{
- priv->context = context ? g_object_ref (context) : NULL;
- priv->context_changed_handler =
- g_signal_connect_object (priv->context,
- "changed",
- G_CALLBACK (on_context_changed),
- chunk,
- 0);
+ if (priv->context_changed_handler)
+ {
+ g_signal_handler_disconnect (priv->context,
+ priv->context_changed_handler);
+ priv->context_changed_handler = 0;
+ }
+
+ g_clear_object (&chunk->priv->context);
+
+ if (context)
+ {
+ priv->context = context ? g_object_ref (context) : NULL;
+ priv->context_changed_handler =
+ g_signal_connect_object (priv->context,
+ "changed",
+ G_CALLBACK (on_context_changed),
+ chunk,
+ 0);
+ }
+
+ g_object_notify_by_pspec (G_OBJECT (chunk), gParamSpecs[PROP_CONTEXT]);
}
-
- g_object_notify_by_pspec (G_OBJECT (chunk), gParamSpecs[PROP_CONTEXT]);
}
const gchar *
diff --git a/src/snippets/gb-source-snippet.c b/src/snippets/gb-source-snippet.c
index 1095a68..9f7a262 100644
--- a/src/snippets/gb-source-snippet.c
+++ b/src/snippets/gb-source-snippet.c
@@ -410,6 +410,7 @@ static void
gb_source_snippet_update_context (GbSourceSnippet *snippet)
{
GbSourceSnippetPrivate *priv;
+ GbSourceSnippetContext *context;
GbSourceSnippetChunk *chunk;
const gchar *text;
gchar key[12];
@@ -422,7 +423,9 @@ gb_source_snippet_update_context (GbSourceSnippet *snippet)
priv = snippet->priv;
- gb_source_snippet_context_emit_changed (priv->context);
+ context = gb_source_snippet_get_context (snippet);
+
+ gb_source_snippet_context_emit_changed (context);
for (i = 0; i < priv->chunks->len; i++)
{
@@ -434,12 +437,12 @@ gb_source_snippet_update_context (GbSourceSnippet *snippet)
{
g_snprintf (key, sizeof key, "%d", tab_stop);
key[sizeof key - 1] = '\0';
- gb_source_snippet_context_add_variable (priv->context, key, text);
+ gb_source_snippet_context_add_variable (context, key, text);
}
}
}
- gb_source_snippet_context_emit_changed (priv->context);
+ gb_source_snippet_context_emit_changed (context);
EXIT;
}
@@ -450,6 +453,7 @@ gb_source_snippet_begin (GbSourceSnippet *snippet,
GtkTextIter *iter)
{
GbSourceSnippetPrivate *priv;
+ GbSourceSnippetContext *context;
GbSourceSnippetChunk *chunk;
const gchar *text;
gboolean ret;
@@ -469,8 +473,10 @@ gb_source_snippet_begin (GbSourceSnippet *snippet,
priv->inserted = TRUE;
+ context = gb_source_snippet_get_context (snippet);
+
gb_source_snippet_update_context (snippet);
- gb_source_snippet_context_emit_changed (priv->context);
+ gb_source_snippet_context_emit_changed (context);
gb_source_snippet_update_context (snippet);
priv->buffer = g_object_ref (buffer);
@@ -830,6 +836,20 @@ gb_source_snippet_get_context (GbSourceSnippet *snippet)
{
g_return_val_if_fail (GB_IS_SOURCE_SNIPPET (snippet), NULL);
+ if (!snippet->priv->context)
+ {
+ GbSourceSnippetChunk *chunk;
+ guint i;
+
+ snippet->priv->context = gb_source_snippet_context_new ();
+
+ for (i = 0; i < snippet->priv->chunks->len; i++)
+ {
+ chunk = g_ptr_array_index (snippet->priv->chunks, i);
+ gb_source_snippet_chunk_set_context (chunk, snippet->priv->context);
+ }
+ }
+
return snippet->priv->context;
}
@@ -995,5 +1015,4 @@ gb_source_snippet_init (GbSourceSnippet *snippet)
snippet->priv->max_tab_stop = -1;
snippet->priv->chunks = g_ptr_array_new_with_free_func (g_object_unref);
snippet->priv->runs = g_array_new (FALSE, FALSE, sizeof (gint));
- snippet->priv->context = gb_source_snippet_context_new ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]