[glib/wip/matthiasc/try-inlining-magic] Add an inline version of g_strcmp0
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/matthiasc/try-inlining-magic] Add an inline version of g_strcmp0
- Date: Sun, 2 Oct 2022 23:32:16 +0000 (UTC)
commit 17e4e5804878af08bff26968ecf2fd99c5317884
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Oct 2 17:02:21 2022 -0400
Add an inline version of g_strcmp0
This can be a significant optimization, since
compilers know how to optimize strcmp, and
inlining g_strcmp0 will make the strcmp call
visible to the compiler at the call site.
glib/gtestutils.c | 43 +++++++++++++++++++------------------------
glib/gtestutils.h | 13 ++++++++++---
2 files changed, 29 insertions(+), 27 deletions(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index de70e921ad..7730c77c91 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -19,8 +19,27 @@
*/
#include "config.h"
+#include "gversionmacros.h"
+
+/**
+ * g_strcmp0:
+ * @str1: (nullable): a C string or %NULL
+ * @str2: (nullable): another C string or %NULL
+ *
+ * Compares @str1 and @str2 like strcmp(). Handles %NULL
+ * gracefully by sorting it before non-%NULL strings.
+ * Comparing two %NULL pointers returns 0.
+ *
+ * Returns: an integer less than, equal to, or greater than zero, if @str1 is <, == or > than @str2.
+ *
+ * Since: 2.16
+ */
+
+GLIB_AVAILABLE_IN_ALL
+int g_strcmp0 (const char *str1, const char *str2);
#include "gtestutils.h"
+
#include "gfileutils.h"
#include <sys/types.h>
@@ -3397,30 +3416,6 @@ g_assertion_message_error (const char *domain,
g_string_free (gstring, TRUE);
}
-/**
- * g_strcmp0:
- * @str1: (nullable): a C string or %NULL
- * @str2: (nullable): another C string or %NULL
- *
- * Compares @str1 and @str2 like strcmp(). Handles %NULL
- * gracefully by sorting it before non-%NULL strings.
- * Comparing two %NULL pointers returns 0.
- *
- * Returns: an integer less than, equal to, or greater than zero, if @str1 is <, == or > than @str2.
- *
- * Since: 2.16
- */
-int
-g_strcmp0 (const char *str1,
- const char *str2)
-{
- if (!str1)
- return -(str1 != str2);
- if (!str2)
- return str1 != str2;
- return strcmp (str1, str2);
-}
-
static void
test_trap_clear (void)
{
diff --git a/glib/gtestutils.h b/glib/gtestutils.h
index 4e38eb4146..c7f147c48c 100644
--- a/glib/gtestutils.h
+++ b/glib/gtestutils.h
@@ -238,9 +238,16 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
} G_STMT_END
#endif /* !G_DISABLE_ASSERT */
-GLIB_AVAILABLE_IN_ALL
-int g_strcmp0 (const char *str1,
- const char *str2);
+inline int
+g_strcmp0 (const char *str1,
+ const char *str2)
+{
+ if (!str1)
+ return -(str1 != str2);
+ if (!str2)
+ return str1 != str2;
+ return strcmp (str1, str2);
+}
/* report performance results */
GLIB_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]