Giter VIP home page Giter VIP logo

Comments (5)

Quuxplusone avatar Quuxplusone commented on July 27, 2024

Hmm. That's true, but isn't there a slippery slope here, given that every macro in uthash.h evaluates its arguments multiple times? In the general case, we ought to pull out every macro argument into a local variable, e.g.

#define HASH_VALUE(keyptr,keylen,hashv)                                          \
do {                                                                             \
  HASH_FCN(keyptr, keylen, hashv);                                               \
} while (0)

arguably ought to be

#define HASH_VALUE(keyptr,keylen,hashv)                                          \
do {                                                                             \
  const void *_hv_keyptr = (const void *)(keyptr);                               \
  unsigned _hv_keylen = (keylen);                                                \
  unsigned *_hv_hashv = &(hashv);                                                \
  HASH_FCN(_hv_keyptr, _hv_keylen, *_hv_hashv);                                  \
} while (0)

in order to avoid pessimizing user code like HASH_VALUE(message(i), strlen(message(i)), hasharr[i % hasharr_size()]). At a certain point we have to say "okay, the user should just rewrite their code to use a local variable themselves; they know this stuff is all macros." The question is just where is that point?

Arguably the difference here is that it's possible for user code to use HASH_VALUE efficiently by judicious use of local variables in user code; but it is currently not possible to use HASH_ADD_STR efficiently at all. So HASH_ADD_STR merits fixing and HASH_VALUE doesn't. What's your take on the situation?

from uthash.

tbeu avatar tbeu commented on July 27, 2024

I definitely would not touch macros like HASH_VALUE as long as the user has the chance to use local variables in his/her own code when calling the macro. However, it is impossible to do so when calling convenience macros like HASH_FIND_STR, HASH_ADD_STR and HASH_REPLACE_STR. Thus, I'd update only the necessary ones.

from uthash.

tbeu avatar tbeu commented on July 27, 2024

PVS-Studio reports:

  • V814 Decreased performance. The 'strlen' function was called multiple times inside the body of a loop.

from uthash.

tbeu avatar tbeu commented on July 27, 2024

Any chance? PR welcome?

from uthash.

Quuxplusone avatar Quuxplusone commented on July 27, 2024

PR welcome.

from uthash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.