Ticket #2290: mc-4.8.10-refresh-size+time.patch

File mc-4.8.10-refresh-size+time.patch, 3.0 KB (added by sknaumov, 6 years ago)

New patch to optimize updates in status bar during search (based on examining file size and time of the last status update). This version is synchronous and is based on assumption that relatively small files are quickly processed even on slow hardware so if refresh timeout expires during their processing, the delay couldn't be noticed by human. Therefore only rather big files have to be reported unconditionally, and others - only if there is a match in this file or if timeout expires.

  • src/filemanager/find.c

    diff -uNr mc-4.8.10.configured/src/filemanager/find.c mc-4.8.10.refresh-size+time/src/filemanager/find.c
    old new  
    149149static gboolean is_start = FALSE;       /* Status of the start/stop toggle button */ 
    150150static char *old_dir = NULL; 
    151151 
     152#define MAX_REFRESH_INTERVAL  50000000     /* 50 ms */ 
     153#define MIN_REFRESH_FILE_SIZE (256 * 1024) /* 256 KB */ 
     154static struct timespec last_refresh; 
     155 
    152156/* Where did we stop */ 
    153157static gboolean resuming; 
    154158static int last_line; 
     
    978982    int file_fd; 
    979983    gboolean ret_val = FALSE; 
    980984    vfs_path_t *vpath; 
     985    struct timespec tv; 
     986    time_t seconds; 
     987    long nanoseconds; 
     988    gboolean status_updated = FALSE; 
    981989 
    982990    vpath = vfs_path_build_filename (directory, filename, (char *) NULL); 
    983991 
     
    9931001    if (file_fd == -1) 
    9941002        return FALSE; 
    9951003 
    996     g_snprintf (buffer, sizeof (buffer), _("Grepping in %s"), filename); 
    997     status_update (str_trunc (buffer, WIDGET (h)->cols - 8)); 
     1004    /* get time elapsed from last refresh */ 
     1005    if (-1 == clock_gettime(CLOCK_MONOTONIC, &tv)) { 
     1006        tv.tv_sec = 0; 
     1007        tv.tv_nsec = 0; 
     1008        last_refresh = tv; 
     1009    } 
     1010    seconds = tv.tv_sec - last_refresh.tv_sec; 
     1011    nanoseconds = tv.tv_nsec - last_refresh.tv_nsec; 
     1012    if (nanoseconds < 0) { 
     1013        seconds -= 1; 
     1014        nanoseconds += 1000000000; 
     1015    } 
     1016 
     1017    if (s.st_size >= MIN_REFRESH_FILE_SIZE || 
     1018        seconds > 0 || 
     1019        nanoseconds > MAX_REFRESH_INTERVAL) 
     1020    { 
     1021        g_snprintf (buffer, sizeof (buffer), _("Grepping in %s"), filename); 
     1022        status_update (str_trunc (buffer, WIDGET (h)->cols - 8)); 
    9981023 
    999     mc_refresh (); 
     1024        mc_refresh (); 
     1025        last_refresh = tv; 
     1026        status_updated = TRUE; 
     1027    } 
    10001028 
    10011029    tty_enable_interrupt_key (); 
    10021030    tty_got_interrupt (); 
     
    10631091                && mc_search_run (search_content_handle, 
    10641092                                  (const void *) strbuf, 0, i, &found_len)) 
    10651093            { 
     1094                if (status_updated == FALSE) { 
     1095                    /* if we add results for a file, we have to ensure that 
     1096                       name of this file is shown in status bar */ 
     1097                    g_snprintf (result, sizeof (result), _("Grepping in %s"), filename); 
     1098                    status_update (str_trunc (result, WIDGET (h)->cols - 8)); 
     1099                    mc_refresh (); 
     1100                    last_refresh = tv; 
     1101                    status_updated = TRUE; 
     1102                } 
     1103 
    10661104                g_snprintf (result, sizeof (result), "%d:%s", line, filename); 
    10671105                find_add_match (directory, result); 
    10681106                found = TRUE; 
     
    18041842        if (pattern[0] == '\0') 
    18051843            break;              /* nothing search */ 
    18061844 
     1845        last_refresh.tv_sec = 0; 
     1846        last_refresh.tv_nsec = 0; 
     1847 
    18071848        dirname = filename = NULL; 
    18081849        is_start = FALSE; 
    18091850        clock_gettime(CLOCK_MONOTONIC, &begin);