> if(file && *file) { I used stlen() > 0 because it is more expressive and clearly indicates the intent. And yes, in modern days most compilers will optimize it.
But if the consensus is that the "if(file && *file)" is better than "if(file && strlen(file) > 0)" then we can go that way. (Personally, I would prefer using some macro like "is_empty_str(file)" instead of *file, but it probably doesn't make sense to create it just for one case) > Are you able to turn this into a PR? Sure, I can create a PR. Thanks, Dmitry Karpov -----Original Message----- From: curl-library <curl-library-boun...@lists.haxx.se> On Behalf Of Daniel Gustafsson via curl-library Sent: Wednesday, December 13, 2023 2:11 PM To: libcurl development <curl-library@lists.haxx.se> Cc: Daniel Gustafsson <dan...@yesql.se> Subject: [EXTERNAL] Re: Empty file name in CURLOPT_COOKIEFILE optimization > On 13 Dec 2023, at 22:53, Dan Fandrich via curl-library > <curl-library@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.html -- Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library Etiquette: https://curl.se/mail/etiquette.html