From e3ea8ecd33fd1815c8e219af92b807fd81b533eb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Jan 2019 09:57:34 +0100 Subject: [PATCH] shared: add NM_STR_HAS_PREFIX() macro Commonly, the prefix is a string constant. We don't need to call g_str_has_prefix() for that, which first requires strlen() on the prefix. All the information is readily available. Add a macro for that. --- shared/nm-utils/nm-macros-internal.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 7cebd56cc0..3578a55291 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -829,6 +829,9 @@ fcn (void) \ #define nm_streq(s1, s2) (strcmp (s1, s2) == 0) #define nm_streq0(s1, s2) (g_strcmp0 (s1, s2) == 0) +#define NM_STR_HAS_PREFIX(str, prefix) \ + (strncmp ((str), ""prefix"", NM_STRLEN (prefix)) == 0) + /*****************************************************************************/ static inline GString *