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) |
133 | 133 | |
134 | 134 | /* --------------------------------------------------------------------------------------------- */ |
135 | 135 | /** |
| 136 | * @returns FALSE = failure, TRUE = success |
| 137 | */ |
| 138 | |
| 139 | static gboolean |
| 140 | grow_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 | /** |
136 | 157 | * If you change handle_dirent then check also handle_path. |
137 | 158 | * @returns -1 = failure, 0 = don't add, 1 = add to the list |
138 | 159 | */ |
… |
… |
handle_dirent (dir_list * list, const char *fltr, struct dirent *dp, |
183 | 204 | return 0; |
184 | 205 | |
185 | 206 | /* 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 | |
193 | 210 | return 1; |
194 | 211 | } |
195 | 212 | |
… |
… |
gboolean |
456 | 473 | set_zero_dir (dir_list * list) |
457 | 474 | { |
458 | 475 | /* 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; |
467 | 478 | |
468 | 479 | memset (&(list->list)[0], 0, sizeof (file_entry)); |
469 | 480 | list->list[0].fnamelen = 2; |
… |
… |
handle_path (dir_list * list, const char *path, |
521 | 532 | vfs_path_free (vpath); |
522 | 533 | |
523 | 534 | /* 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 | |
531 | 538 | return 1; |
532 | 539 | } |
533 | 540 | |