[gtksourceview] buffer: rearm timers instead of remove/add
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] buffer: rearm timers instead of remove/add
- Date: Mon, 1 Aug 2022 19:57:31 +0000 (UTC)
commit b057a1e45a9a2aadb6527fe0491b0aacd41445da
Author: Christian Hergert <chergert redhat com>
Date: Mon Aug 1 12:53:05 2022 -0700
buffer: rearm timers instead of remove/add
For things that can happen at high-velocity, it is cheaper to change the
ready time on a GTimeoutSource than it is to remove/add a new GSource.
While loading should probably disable bracket highlights altogether, this
is a reasonable thing to have anyway for code paths that don't use helpers
to load/unload buffer contents.
Related GNOME/gnome-text-editor#444
gtksourceview/gtksourcebuffer.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index dd6f6f17..ca36d846 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -112,7 +112,7 @@
* read the no-spell-check region).
*/
-#define UPDATE_BRACKET_DELAY 50
+#define UPDATE_BRACKET_DELAY_MSEC 50
#define BRACKET_MATCHING_CHARS_LIMIT 10000
#define CONTEXT_CLASSES_PREFIX "gtksourceview:context-classes:"
@@ -974,9 +974,18 @@ queue_bracket_highlighting_update (GtkSourceBuffer *buffer)
{
GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+ /* Rearm existing GSource when possible */
if (priv->bracket_highlighting_timeout_id != 0)
{
- g_source_remove (priv->bracket_highlighting_timeout_id);
+ GSource *source;
+ gint64 ready_time;
+
+ ready_time = g_get_monotonic_time () +
+ (G_USEC_PER_SEC / 1000L) * UPDATE_BRACKET_DELAY_MSEC;
+
+ source = g_main_context_find_source_by_id (NULL, priv->bracket_highlighting_timeout_id);
+ g_source_set_ready_time (source, ready_time);
+ return;
}
/* Queue an update to the bracket location instead of doing it
@@ -998,7 +1007,7 @@ queue_bracket_highlighting_update (GtkSourceBuffer *buffer)
*/
priv->bracket_highlighting_timeout_id =
g_timeout_add_full (G_PRIORITY_LOW,
- UPDATE_BRACKET_DELAY,
+ UPDATE_BRACKET_DELAY_MSEC,
bracket_highlighting_timeout_cb,
buffer,
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]