From 767b104fb7f8c8a9cbea5f0c97e39257567d3f75 Mon Sep 17 00:00:00 2001 From: Ken Gaillot Date: Jun 10 2020 17:56:11 +0000 Subject: Refactor: libcrmcommon: convenience functions for list length comparisons ... for efficiency and readability --- diff --git a/include/crm/common/internal.h b/include/crm/common/internal.h index da2c7d7..484c836 100644 --- a/include/crm/common/internal.h +++ b/include/crm/common/internal.h @@ -126,6 +126,20 @@ crm_getpid_s() return crm_strdup_printf("%lu", (unsigned long) getpid()); } +// More efficient than g_list_length(list) == 1 +static inline bool +pcmk__list_of_1(GList *list) +{ + return list && (list->next == NULL); +} + +// More efficient than g_list_length(list) > 1 +static inline bool +pcmk__list_of_multiple(GList *list) +{ + return list && (list->next != NULL); +} + /* convenience functions for failure-related node attributes */ #define CRM_FAIL_COUNT_PREFIX "fail-count"