Skip to content

Commit 0ec1f5b

Browse files
jeffhostetlerdscho
authored andcommitted
string-list: use ALLOC_GROW macro when reallocing string_list
Use ALLOC_GROW() macro when reallocing a string_list array rather than simply increasing it by 32. This is a performance optimization. During status on a very large repo and there are many changes, a significant percentage of the total run time was spent reallocing the wt_status.changes array. This change decreased the time in wt_status_collect_changes_worktree() from 125 seconds to 45 seconds on my very large repository. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 308469d commit 0ec1f5b

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

string-list.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ static int add_entry(int insert_at, struct string_list *list, const char *string
4141
if (exact_match)
4242
return -1 - index;
4343

44-
if (list->nr + 1 >= list->alloc) {
45-
list->alloc += 32;
46-
REALLOC_ARRAY(list->items, list->alloc);
47-
}
44+
if (list->nr + 1 >= list->alloc)
45+
ALLOC_GROW(list->items, list->nr+1, list->alloc);
4846
if (index < list->nr)
4947
memmove(list->items + index + 1, list->items + index,
5048
(list->nr - index)

0 commit comments

Comments
 (0)