[gtk/ebassi/lazier-a11y: 1/2] a11y: Avoid signal emission during cache population




commit 0bde58ffd7a72c708102f943a3ed8eaf929a31c1
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Jan 21 16:31:28 2021 +0000

    a11y: Avoid signal emission during cache population
    
    If we're responding to a request to get all the cached items, there's no
    need to emit signals when adding an ATContext to the cache.

 gtk/a11y/gtkatspicache.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/gtk/a11y/gtkatspicache.c b/gtk/a11y/gtkatspicache.c
index 10736341e5..e1c7b5d628 100644
--- a/gtk/a11y/gtkatspicache.c
+++ b/gtk/a11y/gtkatspicache.c
@@ -58,6 +58,9 @@ struct _GtkAtSpiCache
 
   /* HashTable<GtkAtSpiContext, str> */
   GHashTable *contexts_to_path;
+
+  /* Re-entrancy guard */
+  gboolean in_get_items;
 };
 
 enum
@@ -250,10 +253,17 @@ handle_cache_method (GDBusConnection       *connection,
     {
       GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("(" GET_ITEMS_SIGNATURE ")"));
 
+      /* Prevent the emission os signals while collecting accessible
+       * objects as the result of walking the accessible tree
+       */
+      self->in_get_items = TRUE;
+
       g_variant_builder_open (&builder, G_VARIANT_TYPE (GET_ITEMS_SIGNATURE));
       collect_cached_objects (self, &builder);
       g_variant_builder_close (&builder);
 
+      self->in_get_items = FALSE;
+
       g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
     }
 }
@@ -371,7 +381,11 @@ gtk_at_spi_cache_add_context (GtkAtSpiCache   *self,
 
   GTK_NOTE (A11Y, g_message ("Adding context '%s' to cache", path_key));
 
-  emit_add_accessible (self, context);
+  /* GetItems is safe from re-entrancy, but we still don't want to
+   * emit an unnecessary signal while we're collecting ATContexts
+   */
+  if (!self->in_get_items)
+    emit_add_accessible (self, context);
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]