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: Empty file name in CURLOPT_COOKIEFILE optimization
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]
From: Daniel Gustafsson via curl-library <curl-library_at_lists.haxx.se>
Date: Wed, 13 Dec 2023 23:10:53 +0100
> On 13 Dec 2023, at 22:53, Dan Fandrich via curl-library <curl-library_at_lists.haxx.se> wrote:
>
> On Wed, Dec 13, 2023 at 09:49:07PM +0000, Dmitry Karpov via curl-library wrote:
>> I propose to add a simple check for the cookie file name length and call fopen() only if it is greater than zero like:
>
> Sounds reasonable.
>
>> if(data) {
>> FILE *fp = NULL;
>> - if(file) {
>> + if(file && strlen(file) > 0) {
>> if(!strcmp(file, "-"))
>
> This forces a traversal of the entire string, which isn't necessary. This would
> be much faster:
>
> if(file && *file) {
Not necessarily, most compilers will optimize if(strlen(file)>0) into the
equivalent of if(*file) even at -O0 optimization level (even GCC 4.1 does that
according to godbolt.org). It might still be worth doing though for more
arcane compilers on platforms that curl build on.
> Are you able to turn this into a PR?
+1
Date: Wed, 13 Dec 2023 23:10:53 +0100
> On 13 Dec 2023, at 22:53, Dan Fandrich via curl-library <curl-library_at_lists.haxx.se> wrote:
>
> On Wed, Dec 13, 2023 at 09:49:07PM +0000, Dmitry Karpov via curl-library wrote:
>> I propose to add a simple check for the cookie file name length and call fopen() only if it is greater than zero like:
>
> Sounds reasonable.
>
>> if(data) {
>> FILE *fp = NULL;
>> - if(file) {
>> + if(file && strlen(file) > 0) {
>> if(!strcmp(file, "-"))
>
> This forces a traversal of the entire string, which isn't necessary. This would
> be much faster:
>
> if(file && *file) {
Not necessarily, most compilers will optimize if(strlen(file)>0) into the
equivalent of if(*file) even at -O0 optimization level (even GCC 4.1 does that
according to godbolt.org). It might still be worth doing though for more
arcane compilers on platforms that curl build on.
> Are you able to turn this into a PR?
+1
-- Daniel Gustafsson -- Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library Etiquette: https://curl.se/mail/etiquette.htmlReceived on 2023-12-13