[gtksourceview] bufferoutputstream: disbale cursor-moved while writing



commit be1764db9ca922add0c71036556ced044eb4b7a7
Author: Christian Hergert <chergert redhat com>
Date:   Mon Aug 1 13:33:07 2022 -0700

    bufferoutputstream: disbale cursor-moved while writing
    
    We can disable the cursor-moved completely while writing to the buffer,
    particularly to improve the situation when fallbacks are used. This helps
    reduce how much callback work is done by applications.
    
    When the block count reaches zero (which could happen in the epilog of this
    function), the buffer will emit cursor-moved so that applications can
    handle this as if it were a single change.

 gtksourceview/gtksourcebufferoutputstream.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
---
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index 730e03a6..b00e19c3 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -889,18 +889,27 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
        gchar *text;
        gsize len;
        gboolean freetext = FALSE;
+       gboolean blocked = FALSE;
        gssize ret = -1;
 
        GTK_SOURCE_PROFILER_BEGIN_MARK
 
        ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
 
+       if (ostream->source_buffer == NULL)
+       {
+               goto failure;
+       }
+
        if (g_cancellable_set_error_if_cancelled (cancellable, error) ||
            ostream->source_buffer == NULL)
        {
                goto failure;
        }
 
+       blocked = TRUE;
+       _gtk_source_buffer_block_cursor_moved (ostream->source_buffer);
+
        if (!ostream->is_initialized)
        {
                ostream->charset_conv = guess_encoding (ostream, buffer, count);
@@ -1070,6 +1079,11 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
        ret = (gssize)count;
 
 failure:
+       if (blocked)
+       {
+               _gtk_source_buffer_unblock_cursor_moved (ostream->source_buffer);
+       }
+
        GTK_SOURCE_PROFILER_END_MARK ("BufferOutputStream", "gtk_source_buffer_output_stream_write");
 
        return ret;


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