diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-12-06 12:02:55 +0000 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-12-06 12:02:55 +0000 |
commit | bd6a63966762f7fdcf5f9cd86bc50f7f0a9515e2 (patch) | |
tree | 7060296a2c79f98488d865ad72feba4bb508bf3f /common | |
parent | Fix command list execution (diff) | |
download | sway-bd6a63966762f7fdcf5f9cd86bc50f7f0a9515e2.tar.gz sway-bd6a63966762f7fdcf5f9cd86bc50f7f0a9515e2.tar.zst sway-bd6a63966762f7fdcf5f9cd86bc50f7f0a9515e2.zip |
list: double list capacity when resizing instead of incrementing
This is the industry standard since it allows insertion to be amortized
O(1) time.
Diffstat (limited to 'common')
-rw-r--r-- | common/list.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/common/list.c b/common/list.c index ee268c9a..66cf133b 100644 --- a/common/list.c +++ b/common/list.c | |||
@@ -17,7 +17,7 @@ list_t *create_list(void) { | |||
17 | 17 | ||
18 | static void list_resize(list_t *list) { | 18 | static void list_resize(list_t *list) { |
19 | if (list->length == list->capacity) { | 19 | if (list->length == list->capacity) { |
20 | list->capacity += 10; | 20 | list->capacity *= 2; |
21 | list->items = realloc(list->items, sizeof(void*) * list->capacity); | 21 | list->items = realloc(list->items, sizeof(void*) * list->capacity); |
22 | } | 22 | } |
23 | } | 23 | } |