shared/hash: implement nm_hash_obfuscate_ptr() as inline function instead of macro

There is really no reason for this to be a macro. Our hash-related
helpers (like nm_hash_update_val()) are macros because they do some
shenigans to accept arguments of different (compile-time) types. But
the arguments for nm_hash_obfuscate_ptr() are well known and expected
of a certain form.

Note that with "-O2" some quick testing shows that the compiler no
longer inlines the function. But I guess that's fine, probably the
compiler knows best anyway.
This commit is contained in:
Thomas Haller 2019-08-23 11:29:32 +02:00
parent aa100d89a4
commit a63f9aad25

View file

@ -311,15 +311,15 @@ gboolean nm_pdirect_equal (gconstpointer a, gconstpointer b);
*
* Note that there is a chance that two different pointer values hash to the same obfuscated
* value. So beware of that when reviewing logs. However, such a collision is very unlikely. */
#define nm_hash_obfuscate_ptr(static_seed, val) \
({ \
NMHashState _h; \
const void *_val_obf_ptr = (val); \
\
nm_hash_init (&_h, (static_seed)); \
nm_hash_update_val (&_h, _val_obf_ptr); \
nm_hash_complete_u64 (&_h); \
})
static inline guint64
nm_hash_obfuscate_ptr (guint static_seed, gconstpointer val)
{
NMHashState h;
nm_hash_init (&h, static_seed);
nm_hash_update_val (&h, val);
return nm_hash_complete_u64 (&h);
}
/* if you want to log obfuscated pointer for a certain context (like, NMPRuleManager
* logging user-tags), then you are advised to use nm_hash_obfuscate_ptr() with your