mirror of https://github.com/MidnightCommander/mc
Ticket #2888: code cleanup before 4.8.7 release.
src/filemanager/dir.c: refactored growing of dir_list into a separate function. Signed-off-by: Yury V. Zaytsev <yury@shurup.com> Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
45b129dd72
commit
994c432dd5
|
@ -115,7 +115,9 @@ key_collate (const char *t1, const char *t2)
|
|||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** clear keys, should be call after sorting is finished */
|
||||
/**
|
||||
* clear keys, should be call after sorting is finished.
|
||||
*/
|
||||
|
||||
static void
|
||||
clean_sort_keys (dir_list * list, int start, int count)
|
||||
|
@ -131,6 +133,30 @@ clean_sort_keys (dir_list * list, int start, int count)
|
|||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Increase directory list by RESIZE_STEPS
|
||||
*
|
||||
* @param list directory list
|
||||
* @returns FALSE = failure, TRUE = success
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
grow_list (dir_list * list)
|
||||
{
|
||||
if (list == NULL)
|
||||
return FALSE;
|
||||
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
|
||||
|
||||
if (list->list == NULL)
|
||||
return FALSE;
|
||||
|
||||
list->size += RESIZE_STEPS;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* If you change handle_dirent then check also handle_path.
|
||||
|
@ -183,13 +209,9 @@ handle_dirent (dir_list * list, const char *fltr, struct dirent *dp,
|
|||
return 0;
|
||||
|
||||
/* Need to grow the *list? */
|
||||
if (next_free == list->size)
|
||||
{
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
|
||||
if (list->list == NULL)
|
||||
if (next_free == list->size && !grow_list (list))
|
||||
return -1;
|
||||
list->size += RESIZE_STEPS;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -456,15 +478,9 @@ gboolean
|
|||
set_zero_dir (dir_list * list)
|
||||
{
|
||||
/* Need to grow the *list? */
|
||||
if (list->size == 0)
|
||||
{
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
|
||||
if (list->list == NULL)
|
||||
if (list->size == 0 && !grow_list (list))
|
||||
return FALSE;
|
||||
|
||||
list->size += RESIZE_STEPS;
|
||||
}
|
||||
|
||||
memset (&(list->list)[0], 0, sizeof (file_entry));
|
||||
list->list[0].fnamelen = 2;
|
||||
list->list[0].fname = g_strndup ("..", list->list[0].fnamelen);
|
||||
|
@ -521,13 +537,9 @@ handle_path (dir_list * list, const char *path,
|
|||
vfs_path_free (vpath);
|
||||
|
||||
/* Need to grow the *list? */
|
||||
if (next_free == list->size)
|
||||
{
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
|
||||
if (list->list == NULL)
|
||||
if (next_free == list->size && !grow_list (list))
|
||||
return -1;
|
||||
list->size += RESIZE_STEPS;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue