mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
g_str_equal: Provide macro for optimization
g_str_equal() is a nicer API than strcmp()==0, and less error prone. However, forcing a function call prevents compiler from doing optimizations. In the case it is not used as callback to GHashTable, provide a macro that calls strcmp directly. This also has the side effect that it forces arguments to be `const char *` instead of `gconstpointer` in the case it is not used as callback, which adds type safety. Fixes: #2775
This commit is contained in:
parent
ce48bf1abd
commit
6e341750df
@ -2323,7 +2323,7 @@ g_hash_table_get_values (GHashTable *hash_table)
|
||||
* Returns: %TRUE if the two keys match
|
||||
*/
|
||||
gboolean
|
||||
g_str_equal (gconstpointer v1,
|
||||
(g_str_equal) (gconstpointer v1,
|
||||
gconstpointer v2)
|
||||
{
|
||||
const gchar *string1 = v1;
|
||||
|
@ -160,6 +160,10 @@ void g_hash_table_unref (GHashTable *hash_table);
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
gboolean g_str_equal (gconstpointer v1,
|
||||
gconstpointer v2);
|
||||
|
||||
/* Macro for optimization in the case it is not used as callback function */
|
||||
#define g_str_equal(v1, v2) (strcmp ((v1), (v2)) == 0)
|
||||
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
guint g_str_hash (gconstpointer v);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user