Willy,
Christopher,
I did not perform any measurements at all. But not reallocating for every
parameter should be better :-)
Best regards
Tim Düsterhus
Apply with `git am --scissors` to automatically cut the commit message.
-- >8 --
Do not reallocate for each parameter.
---
src/uri_normalizer.c | 16 +++-
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/uri_normalizer.c b/src/uri_normalizer.c
index e7b2b2cd3..8dc74788e 100644
--- a/src/uri_normalizer.c
+++ b/src/uri_normalizer.c
@@ -153,20 +153,26 @@ struct ist uri_normalizer_query_sort(const struct ist
query, const char delim, c
struct ist scanner = istadv(query, 1);
struct ist *params = NULL;
struct ist newquery = ist2(trash, 0);
+ size_t param_size = 128;
size_t param_count = 0;
size_t i;
if (len < istlen(query))
- return IST_NULL;
+ goto fail;
while (istlen(scanner) > 0) {
const struct ist param = istsplit(&scanner, delim);
- struct ist *realloc = reallocarray(params, param_count + 1,
sizeof(*realloc));
- if (!realloc)
- goto fail;
+ if (!params || param_count == param_size) {
+ struct ist *realloc;
+
+ param_size *= 2;
- params = realloc;
+ if (!(realloc = reallocarray(params, param_size,
sizeof(*realloc
+ goto fail;
+
+ params = realloc;
+ }
params[param_count] = param;
param_count++;
--
2.31.1