Ticket #4126: 0006-optimize-bash-cursor-position-translation.patch

File 0006-optimize-bash-cursor-position-translation.patch, 1.2 KB (added by ossi, 4 years ago)
  • src/subshell/common.c

    From 7f5e747874802d69d4bd9f7e9740312ef91e74cc Mon Sep 17 00:00:00 2001
    From: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
    Date: Thu, 8 Oct 2020 13:26:17 +0200
    Subject: [PATCH 6/7] optimize bash cursor position translation
    
    the previous algorithm was O(n^2).
    ---
     src/subshell/common.c | 8 ++++----
     1 file changed, 4 insertions(+), 4 deletions(-)
    
    diff --git a/src/subshell/common.c b/src/subshell/common.c
    index 32577bcb2..b9e04e8ea 100644
    a b read_command_line_buffer (gboolean test_mode) 
    633633    { 
    634634        /* We need to do this because bash gives the cursor position in a utf-8 string based 
    635635         * on the location in bytes, not in unicode characters. */ 
    636         for (i = 0; i < command_buffer_length; i++) 
    637             if (str_offset_to_pos (subshell_command_buffer, i) == cursor_position) 
    638                 break; 
    639         cursor_position = i; 
     636        char *curr = subshell_command_buffer; 
     637        char *stop = curr + cursor_position; 
     638        for (cursor_position = 0; curr < stop; cursor_position++) 
     639            str_next_char_safe (&curr); 
    640640    } 
    641641    if (cursor_position > command_buffer_length) 
    642642        cursor_position = command_buffer_length;