commit 879885a73622ae712b7ce0eb88c2bf9647f45d39
parent 155258e06ea58b30b225c3d17e1aae8f6fb8062c
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 18 May 2025 12:27:18 +0200
tweaks: use reallocations, instead of new allocations plus frees
Probably more than half of the reallocations will be no-ops, so
this should be faster.
Diffstat:
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/history.c b/src/history.c
@@ -353,16 +353,14 @@ void save_history(void)
char *stringify_anchors(void)
{
linestruct *line = openfile->filetop;
- char *string = NULL;
+ char *string = copy_of("");
char number[24];
- if (asprintf(&string, "%s", "") < 0)
- return NULL;
-
for (; line != NULL; line = line->next)
if (line->has_anchor) {
sprintf(number, "%li ", line->lineno);
- string = free_and_assign(string, concatenate(string, number));
+ string = nrealloc(string, strlen(string) + strlen(number) + 1);
+ strcat(string, number);
}
return string;