mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 05:18:23 +02:00
glib-aux: define nm_direct_hash/nm_str_hash as macros
nm_hash_str() has the proper name and signature for that it does. That is, it has a "nm_hash_*" prefix and the parameter is of type "const char *". nm_hash_str() has this name because it is primarily about hashing. For hash tables, glib has g_str_hash() and g_str_equal(). We want to replace g_str_hash() with our implementation (nm_hash_str()) because that uses siphash24 with a random seed. But in those cases we want to use the more familiar name "nm_str_hash()", which reminds of g_str_hash() and follows the pattern of g_str_equal(). Thus: g_hash_table_new(nm_str_hash, g_str_equal); is preferable over g_hash_table_new(nm_hash_str, g_str_equal); Hence, we have (and had) nm_str_hash() effectively an alias to nm_hash_str. The question is: which name is preferable? Or should they be both present for their slightly distinct uses? The approach taken here is to have both names, to reflect their purpose better. But as the usage of nm_str_hash is as function pointer for GHashTable, it was not an inline function and we'd pay a small overhead with this approach of aliasing. Avoid that overhead by defining nm_str_hash with the C preprocessor. For similar reasons, do that for nm_direct_hash.
This commit is contained in:
parent
b8392757ec
commit
c810fe24fe
2 changed files with 2 additions and 14 deletions
|
|
@ -138,12 +138,6 @@ nm_hash_str(const char *str)
|
|||
return nm_hash_complete(&h);
|
||||
}
|
||||
|
||||
guint
|
||||
nm_str_hash(gconstpointer str)
|
||||
{
|
||||
return nm_hash_str(str);
|
||||
}
|
||||
|
||||
guint
|
||||
nm_hash_ptr(gconstpointer ptr)
|
||||
{
|
||||
|
|
@ -156,12 +150,6 @@ nm_hash_ptr(gconstpointer ptr)
|
|||
return nm_hash_complete(&h);
|
||||
}
|
||||
|
||||
guint
|
||||
nm_direct_hash(gconstpointer ptr)
|
||||
{
|
||||
return nm_hash_ptr(ptr);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
guint
|
||||
|
|
|
|||
|
|
@ -201,10 +201,10 @@ nm_hash_update_str(NMHashState *state, const char *str)
|
|||
#endif
|
||||
|
||||
guint nm_hash_ptr(gconstpointer ptr);
|
||||
guint nm_direct_hash(gconstpointer str);
|
||||
#define nm_direct_hash nm_hash_ptr
|
||||
|
||||
guint nm_hash_str(const char *str);
|
||||
guint nm_str_hash(gconstpointer str);
|
||||
#define nm_str_hash ((guint(*)(gconstpointer str)) nm_hash_str)
|
||||
|
||||
#define nm_hash_val(static_seed, val) \
|
||||
({ \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue