Comments (5)
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.
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.
PVS-Studio reports:
- V814 Decreased performance. The 'strlen' function was called multiple times inside the body of a loop.
from uthash.
Any chance? PR welcome?
from uthash.
PR welcome.
from uthash.
Related Issues (20)
- Recommend adding GitHub topics
- Please add the library.properties file to use this library in Arduino without error HOT 1
- HASH_CLEAR-with-deleter
- New release v2.3.0? HOT 3
- Add support for cmake HOT 2
- tests/example segfaults on add user HOT 6
- Consider adding more HASH_FIND_XX for standard INT/UINT types HOT 1
- how to handle lock on HASH_ITER? HOT 1
- Is it feasible for application in MCU with limited RAM? HOT 1
- How to create more than one hash table? HOT 1
- Please update userguide on Website HOT 1
- Integrate Xor filters HOT 4
- "UT_hash_table" is reserved, shoud be mentioned in document HOT 2
- DL_SORT error with gcc 11.2 analyzer
- Replace TravisCI with GitHub Actions or AppVeyor?
- Is ID really needed? HOT 2
- hashscan & core files
- Feature Request: remove reliance on POSIX `strdup` in utarray HOT 1
- CORE in DL_DELETE2 HOT 2
- Quick membership check? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uthash.