tool_writeout: bsearch the variable name

As the list of variable names grows, doing a simple loop to find the
name get increasingly worse. This switches to a bsearch.

Also: do a case sensitive check for the variable name. The names have
not been documented to be case insensitive and there is no point in
having them so.

Closes #13914
This commit is contained in:
Daniel Stenberg 2024-06-10 13:33:16 +02:00
parent 374d178f14
commit 4464c9f2c6
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 78 additions and 59 deletions

View file

@ -101,13 +101,14 @@ void jsonWriteString(FILE *stream, const char *in, bool lowercase)
}
void ourWriteOutJSON(FILE *stream, const struct writeoutvar mappings[],
size_t nentries,
struct per_transfer *per, CURLcode per_result)
{
int i;
size_t i;
fputs("{", stream);
for(i = 0; mappings[i].name != NULL; i++) {
for(i = 0; i < nentries; i++) {
if(mappings[i].writefunc &&
mappings[i].writefunc(stream, &mappings[i], per, per_result, true))
fputs(",", stream);