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: Fri, 4 Feb 2022 18:27:15 +0100

well it depends, if the length is taken often then yes berval like structs
are more efficient and there are most likely a few places in the curl code
(like place holders for settings and so on) where it might make sense.
However if the length is only take once or even twice in the lifetime of a
string then the added size of each string would just make curl less cache
efficient.

/HH

Den fre 4 feb. 2022 kl 18:24 skrev Howard Chu <hyc_at_highlandsun.com>:

> Henrik Holst wrote:
> > looks to be similar but just for the length part, aka from looking at
> OpenLDAP code I can see that one have to use the string literal twice
> >
> > if ( strncasecmp( uri, "uri=", STRLENOF( "uri=" ) ) == 0 ) {
> >
> > while CONSTLEN would be just
> > if ( strncasecmp( uri, CONSTLEN( "uri=" ) ) == 0 ) {
> >
> > Now OpenLDAP probably have a reason for doing it this way, but IMHO
> having to type the string literal twice is error prone.
>
> When initializing a struct berval we use BER_BVC("literal") where BVC
> stood for BerVal Constant.
>
> I think in general you're going to want something like a struct berval
> instead of bare char* strings,
> to really make a difference in efficiency.
> >
> > /HH
> >
> >
> > Den fre 4 feb. 2022 kl 17:32 skrev Howard Chu via curl-library <
> curl-library_at_lists.haxx.se <mailto:curl-library_at_lists.haxx.se>>:
> >
> > Daniel Stenberg via curl-library wrote:
> > > On Fri, 4 Feb 2022, Henrik Holst via curl-library wrote:
> > >
> > >> Just have to have consensus on what to call this macro, looking
> at the codebase there is a strong use of CURL_ prefixes so perhaps
> CURL_CONSTLEN or something
> > >> like that?
> > >
> > > Since the name would be used internally only and it wouldn't
> likely collide with an existing name, I don't think a curl prefix is
> necessary. I even prefer
> > > without then, to make the name shorter and more easily readable.
> > >
> > > CONSTLEN() works for me.
> > >
> > OpenLDAP has done this for ... decades. We called it STRLENOF().
> >
> > --
> > -- Howard Chu
> > CTO, Symas Corp. http://www.symas.com
> > Director, Highland Sun http://highlandsun.com/hyc/
> > Chief Architect, OpenLDAP http://www.openldap.org/project/
> > --
> > Unsubscribe: https://lists.haxx.se/listinfo/curl-library
> > Etiquette: https://curl.haxx.se/mail/etiquette.html
> >
>
>
> --
> -- Howard Chu
> CTO, Symas Corp. http://www.symas.com
> Director, Highland Sun http://highlandsun.com/hyc/
> Chief Architect, OpenLDAP http://www.openldap.org/project/
>


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