From ae663e724774007e0242fc509c87402a3ff7b7c4 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 5 Dec 2020 00:46:51 -0800 Subject: [PATCH] Don't realloc twice when adding to the taggroup --- src/taglist.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index 7dbad65c4..cfd9cbb9c 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -170,16 +170,15 @@ void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id) for (i = 0; i < group->count; i++) if (group->elements[i] > id) break; - - group->elements = Z_Realloc(group->elements, (group->count + 1) * sizeof(size_t), PU_LEVEL, NULL); - - // Offset existing elements to make room for the new one. - if (i < group->count) - memmove(&group->elements[i + 1], &group->elements[i], group->count - i); } + group->elements = Z_Realloc(group->elements, (group->count + 1) * sizeof(size_t), PU_LEVEL, NULL); + + // Offset existing elements to make room for the new one. + if (i < group->count) + memmove(&group->elements[i + 1], &group->elements[i], group->count - i); + group->count++; - group->elements = Z_Realloc(group->elements, group->count * sizeof(size_t), PU_LEVEL, NULL); group->elements[i] = id; }