[Geany-Devel] Implementing stdlib/glib in Geany

Pavel Roschin roshin at xxxxx
Sun Apr 27 20:28:22 UTC 2014

I found interesting function in utils.c:

gboolean utils_str_equal(const gchar *a, const gchar *b)
	/* (taken from libexo from os-cillation) */
	if (a == NULL && b == NULL) return TRUE;
	else if (a == NULL || b == NULL) return FALSE;

	while (*a == *b++)
		if (*a++ == '\0')
			return TRUE;

	return FALSE;

This function is widely used in Geany code.

- it is not inline so there is no reason to keep this small while loop
- it uses own while-loop to compare that is *slow* for big strings
- GLib has similar g_strcmp0 function since 2.16

Using while-loop may confuse compiler which knows strcmp and may optimize this
std call e.g. for constants. Furthermore strcmp is SSE-accelerated function
which compares 128 bits per cycle while this implementstion may compare only 8
bits per cycle.

Replace this by inline (g_strcmp0(a, b) == 0). This is much faster and easier to read.

Best regards,
Pavel Roschin aka RPG

More information about the Devel mailing list