[gnome-builder] git: use encoded form for transfering line changes
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] git: use encoded form for transfering line changes
- Date: Wed, 10 Apr 2019 07:36:51 +0000 (UTC)
commit 850e0d707923b61bda44e6a5a88c42aaeecc76ab
Author: Christian Hergert <chergert redhat com>
Date: Wed Apr 10 00:23:50 2019 -0700
git: use encoded form for transfering line changes
This takes less space and simplfies fixed array usage.
.../git/daemon/ipc-git-change-monitor-impl.c | 4 +--
src/plugins/git/daemon/line-cache.c | 29 ++++++++++++++++------
src/plugins/git/daemon/line-cache.h | 1 +
.../daemon/org.gnome.Builder.Git.ChangeMonitor.xml | 3 ++-
4 files changed, 26 insertions(+), 11 deletions(-)
---
diff --git a/src/plugins/git/daemon/ipc-git-change-monitor-impl.c
b/src/plugins/git/daemon/ipc-git-change-monitor-impl.c
index 656d1888c..b7aa04777 100644
--- a/src/plugins/git/daemon/ipc-git-change-monitor-impl.c
+++ b/src/plugins/git/daemon/ipc-git-change-monitor-impl.c
@@ -239,7 +239,7 @@ ipc_git_change_monitor_impl_handle_list_changes (IpcGitChangeMonitor *monitor,
ret = line_cache_to_variant (cache);
g_assert (ret != NULL);
- g_assert (g_variant_is_of_type (ret, G_VARIANT_TYPE ("a(uu)")));
+ g_assert (g_variant_is_of_type (ret, G_VARIANT_TYPE ("au")));
gerror:
g_assert (ret != NULL || error != NULL);
@@ -247,7 +247,7 @@ gerror:
if (g_error_matches (error, GGIT_ERROR, GIT_ENOTFOUND))
{
g_clear_error (&error);
- ret = g_variant_take_ref (g_variant_new_array (G_VARIANT_TYPE ("(uu)"), NULL, 0));
+ ret = g_variant_take_ref (g_variant_new_array (G_VARIANT_TYPE ("u"), NULL, 0));
}
if (error != NULL && error->domain != G_IO_ERROR)
diff --git a/src/plugins/git/daemon/line-cache.c b/src/plugins/git/daemon/line-cache.c
index fec8c19fd..8a0f47a0f 100644
--- a/src/plugins/git/daemon/line-cache.c
+++ b/src/plugins/git/daemon/line-cache.c
@@ -210,18 +210,31 @@ line_cache_foreach_in_range (const LineCache *self,
GVariant *
line_cache_to_variant (const LineCache *self)
{
- GVariantBuilder builder;
+ g_return_val_if_fail (self != NULL, NULL);
- g_assert (self != NULL);
- g_assert (self->lines != NULL);
+ return g_variant_take_ref (g_variant_new_fixed_array (G_VARIANT_TYPE ("u"),
+ (gconstpointer)self->lines->data,
+ self->lines->len,
+ sizeof (LineEntry)));
+}
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(uu)"));
+LineCache *
+line_cache_new_from_variant (GVariant *variant)
+{
+ LineCache *self;
+
+ self = line_cache_new ();
- for (guint i = 0; i < self->lines->len; i++)
+ if (variant != NULL)
{
- const LineEntry *entry = &g_array_index (self->lines, LineEntry, i);
- g_variant_builder_add (&builder, "(uu)", entry->line, entry->mark);
+ gconstpointer base;
+ gsize n_elements = 0;
+
+ base = g_variant_get_fixed_array (variant, &n_elements, sizeof (LineEntry));
+
+ if (n_elements > 0 && n_elements < G_MAXINT)
+ g_array_append_vals (self->lines, base, n_elements);
}
- return g_variant_take_ref (g_variant_builder_end (&builder));
+ return g_steal_pointer (&self);
}
diff --git a/src/plugins/git/daemon/line-cache.h b/src/plugins/git/daemon/line-cache.h
index 5ba864be8..c6b673dc3 100644
--- a/src/plugins/git/daemon/line-cache.h
+++ b/src/plugins/git/daemon/line-cache.h
@@ -41,6 +41,7 @@ typedef struct
} LineEntry;
LineCache *line_cache_new (void);
+LineCache *line_cache_new_from_variant (GVariant *changes);
void line_cache_free (LineCache *self);
void line_cache_mark_range (LineCache *self,
gint start_line,
diff --git a/src/plugins/git/daemon/org.gnome.Builder.Git.ChangeMonitor.xml
b/src/plugins/git/daemon/org.gnome.Builder.Git.ChangeMonitor.xml
index bdfbdf716..5520c8714 100644
--- a/src/plugins/git/daemon/org.gnome.Builder.Git.ChangeMonitor.xml
+++ b/src/plugins/git/daemon/org.gnome.Builder.Git.ChangeMonitor.xml
@@ -27,7 +27,8 @@
<arg name="contents" direction="in" type="ay"/>
</method>
<method name="ListChanges">
- <arg name="changes" direction="out" type="a(uu)"/>
+ <!-- au is array of encoded changes -->
+ <arg name="changes" direction="out" type="au"/>
</method>
<method name="Close"/>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]