Ticket #2888: 0001-src-filemanager-dir.c-refactored-growing-of-dir_list.patch

File 0001-src-filemanager-dir.c-refactored-growing-of-dir_list.patch, 2.8 KB (added by zaytsev, 12 years ago)
  • src/filemanager/dir.c

    From 56be1a791643eedc47a7f62869223907b84cacd6 Mon Sep 17 00:00:00 2001
    From: "Yury V. Zaytsev" <yury@shurup.com>
    Date: Sun, 28 Oct 2012 12:05:27 +0100
    Subject: [PATCH] src/filemanager/dir.c: refactored growing of dir_list into a
     separate function
    
    Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
    ---
     src/filemanager/dir.c |   51 ++++++++++++++++++++++++++++---------------------
     1 file changed, 29 insertions(+), 22 deletions(-)
    
    diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c
    index afc63d3..6406e6c 100644
    a b clean_sort_keys (dir_list * list, int start, int count) 
    133133 
    134134/* --------------------------------------------------------------------------------------------- */ 
    135135/** 
     136 * @returns FALSE = failure, TRUE = success 
     137 */ 
     138 
     139static gboolean 
     140grow_list (dir_list * list) 
     141{ 
     142    if (list == NULL) 
     143        return FALSE; 
     144 
     145    list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS)); 
     146 
     147    if (list->list == NULL) 
     148        return FALSE; 
     149 
     150    list->size += RESIZE_STEPS; 
     151 
     152    return TRUE; 
     153} 
     154 
     155/* --------------------------------------------------------------------------------------------- */ 
     156/** 
    136157 * If you change handle_dirent then check also handle_path. 
    137158 * @returns -1 = failure, 0 = don't add, 1 = add to the list 
    138159 */ 
    handle_dirent (dir_list * list, const char *fltr, struct dirent *dp, 
    183204        return 0; 
    184205 
    185206    /* Need to grow the *list? */ 
    186     if (next_free == list->size) 
    187     { 
    188         list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS)); 
    189         if (list->list == NULL) 
    190             return -1; 
    191         list->size += RESIZE_STEPS; 
    192     } 
     207    if (next_free == list->size && !grow_list (list)) 
     208        return -1; 
     209 
    193210    return 1; 
    194211} 
    195212 
    gboolean 
    456473set_zero_dir (dir_list * list) 
    457474{ 
    458475    /* Need to grow the *list? */ 
    459     if (list->size == 0) 
    460     { 
    461         list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS)); 
    462         if (list->list == NULL) 
    463             return FALSE; 
    464  
    465         list->size += RESIZE_STEPS; 
    466     } 
     476    if (!list->size && !grow_list (list)) 
     477        return FALSE; 
    467478 
    468479    memset (&(list->list)[0], 0, sizeof (file_entry)); 
    469480    list->list[0].fnamelen = 2; 
    handle_path (dir_list * list, const char *path, 
    521532    vfs_path_free (vpath); 
    522533 
    523534    /* Need to grow the *list? */ 
    524     if (next_free == list->size) 
    525     { 
    526         list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS)); 
    527         if (list->list == NULL) 
    528             return -1; 
    529         list->size += RESIZE_STEPS; 
    530     } 
     535    if (next_free == list->size && !grow_list (list)) 
     536        return -1; 
     537 
    531538    return 1; 
    532539} 
    533540