curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Fewer mallocs is better, episode #47

From: Henrik Holst via curl-library <curl-library_at_lists.haxx.se>
Date: Tue, 1 Feb 2022 12:33:31 +0100

did find one low hanging fruit and one interesting strcpy reimplementation:

henrik_at_Sineya:~/utveckling/repositories/curl$ git diff
diff --git a/lib/base64.c b/lib/base64.c
index be6f163dc..c84d3ca3d 100644
--- a/lib/base64.c
+++ b/lib/base64.c
_at__at_ -273,7 +273,7 _at__at_ static CURLcode base64_encode(const char *table64,
   free(convbuf);

   /* Return the length of the new data */
- *outlen = strlen(base64data);
+ *outlen = output - base64data;

   return CURLE_OK;
 }
diff --git a/lib/urlapi.c b/lib/urlapi.c
index d29aeb238..66d6bf487 100644
--- a/lib/urlapi.c
+++ b/lib/urlapi.c
_at__at_ -1005,9 +1005,7 _at__at_ static CURLUcode seturl(const char *url, CURLU *u,
unsigned int flags)
         return CURLUE_NO_HOST;
     }

- len = strlen(p);
- memcpy(path, p, len);
- path[len] = 0;
+ strcpy(path, p);

     if(schemep) {
       u->scheme = strdup(schemep);

/HH



Den fre 28 jan. 2022 kl 15:52 skrev Henrik Holst <
henrik.holst_at_millistream.com>:

> yes, hence the quotation marks and the "if they even can be reduced"
> caveat ;). I have to look over what curl is calling strlen on, tried to run
> ltrace but the compiled version on Ubuntu seems to be compiled in a way
> that prohibits ltrace from finding any libcalls (it did find syscalls) so
> I'll look later when I have a custom compile of curl.
>
> /HH
>
> Den fre 28 jan. 2022 kl 15:47 skrev Daniel Stenberg <daniel_at_haxx.se>:
>
>> On Fri, 28 Jan 2022, Henrik Holst wrote:
>>
>> > it does "waste" (depending on if they even can be reduced and even then
>> what
>> > the savings would be) cpu time for setting up new connections
>>
>> They are only a waste if we can do the same thing without doing the
>> strlens.
>> I'll willingly work on removing all uncessary strlen calls anyone can
>> find.
>>
>> --
>>
>> / daniel.haxx.se
>> | Commercial curl support up to 24x7 is available!
>> | Private help, bug fixes, support, ports, new features
>> | https://curl.se/support.html
>>
>


-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2022-02-01