Ticket #2290: mc-4.8.9-optimize-status-update.patch

File mc-4.8.9-optimize-status-update.patch, 3.4 KB (added by sknaumov, 11 years ago)
  • src/filemanager/find.c

    diff -uNr mc-4.8.9/src/filemanager/find.c mc-4.8.9.status/src/filemanager/find.c
    old new  
    3838#include <string.h> 
    3939#include <fcntl.h> 
    4040#include <sys/stat.h> 
     41#include <unistd.h> 
     42#include <signal.h> 
    4143 
    4244#include "lib/global.h" 
    4345 
     
    154156static int last_line; 
    155157static int last_pos; 
    156158 
     159static gboolean refresh_status; 
     160 
    157161static size_t ignore_count = 0; 
    158162 
    159163static WDialog *find_dlg;       /* The dialog */ 
     
    10131017    return FIND_CONT; 
    10141018} 
    10151019 
     1020/* use alarm to make status updates only once per second */ 
     1021void set_refresh_and_alarm(int sig) { 
     1022    refresh_status = TRUE; 
     1023    alarm(1); 
     1024} 
     1025 
    10161026/* --------------------------------------------------------------------------------------------- */ 
    10171027/** 
    10181028 * search_content: 
     
    10471057    if (file_fd == -1) 
    10481058        return FALSE; 
    10491059 
    1050     g_snprintf (buffer, sizeof (buffer), _("Grepping in %s"), filename); 
    1051     status_update (str_trunc (buffer, WIDGET (h)->cols - 8)); 
    1052  
    1053     mc_refresh (); 
    1054  
    10551060    tty_enable_interrupt_key (); 
    10561061    tty_got_interrupt (); 
    10571062 
     
    10641069        gboolean found = FALSE; 
    10651070        gsize found_len; 
    10661071        char result[BUF_MEDIUM]; 
     1072        gboolean status_updated = FALSE; 
    10671073 
    10681074        if (resuming) 
    10691075        { 
     
    10761082               && (p = get_line_at (file_fd, buffer, sizeof (buffer), 
    10771083                                    &pos, &n_read, &has_newline)) != NULL) 
    10781084        { 
     1085            if (refresh_status == TRUE && status_updated == FALSE) { 
     1086                g_snprintf (buffer, sizeof (buffer), _("Grepping in %s/%s"), directory, filename); 
     1087                status_update (str_trunc (buffer, WIDGET (h)->cols - 8)); 
     1088                mc_refresh (); 
     1089                status_updated = TRUE; 
     1090                refresh_status = FALSE; 
     1091            } 
    10791092            if (!found          /* Search in binary line once */ 
    10801093                && mc_search_run (search_content_handle, 
    10811094                                  (const void *) p, 0, strlen (p), &found_len)) 
     
    12821295                g_free (directory); 
    12831296                directory = g_strdup (vfs_path_as_str (tmp_vpath)); 
    12841297 
     1298                /* //directory is shown along with file name now 
    12851299                if (verbose) 
    12861300                { 
    12871301                    char buffer[BUF_MEDIUM]; 
     
    12891303                    g_snprintf (buffer, sizeof (buffer), _("Searching %s"), directory); 
    12901304                    status_update (str_trunc (directory, WIDGET (h)->cols - 8)); 
    12911305                } 
     1306                */ 
    12921307                /* mc_stat should not be called after mc_opendir 
    12931308                   because vfs_s_opendir modifies the st_nlink 
    12941309                 */ 
     
    16691684{ 
    16701685    int return_value = 0; 
    16711686    char *dir_tmp = NULL, *file_tmp = NULL; 
    1672  
    16731687    setup_gui (); 
    16741688 
    16751689    /* FIXME: Need to cleanup this, this ought to be passed non-globaly */ 
     
    16791693    if (options.content_use && content != NULL && str_is_valid_string (content)) 
    16801694        content_pattern = g_strdup (content); 
    16811695 
     1696    signal(SIGALRM, set_refresh_and_alarm); 
     1697    set_refresh_and_alarm(SIGALRM); 
     1698 
    16821699    init_find_vars (); 
    16831700    parse_ignore_dirs (ignore_dirs); 
    16841701    push_directory (vfs_path_from_str (start_dir)); 
     
    17941811    g_free (old_dir); 
    17951812    old_dir = NULL; 
    17961813    rotate_dash (FALSE); 
     1814    alarm(0); 
    17971815 
    17981816    return return_value; 
    17991817}