From c29e3410c9ea903d9f23032f91481ac4cc48179e Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 9 Oct 2024 17:16:44 +0200 Subject: [PATCH] device_mapper: slight improvement of tok_match Reduce amount of unnecessary instructions for some code paths. --- device_mapper/libdm-config.c | 10 +++++++--- libdm/libdm-config.c | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/device_mapper/libdm-config.c b/device_mapper/libdm-config.c index b29509b9f..1c1d6d9d0 100644 --- a/device_mapper/libdm-config.c +++ b/device_mapper/libdm-config.c @@ -85,14 +85,18 @@ static char *_dup_token(struct dm_pool *mem, const char *b, const char *e); } \ } while(0) +/* match token */ static int _tok_match(const char *str, const char *b, const char *e) { - while (*str && (b != e)) { - if (*str++ != *b++) + while (b < e) { + if (!*str || + (*str != *b)) return 0; + ++str; + ++b; } - return !(*str || (b != e)); + return !*str; /* token is matching for \0 end */ } struct dm_config_tree *dm_config_create(void) diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c index fc65fb98f..7ae2e1a98 100644 --- a/libdm/libdm-config.c +++ b/libdm/libdm-config.c @@ -85,14 +85,18 @@ static char *_dup_token(struct dm_pool *mem, const char *b, const char *e); } \ } while(0) +/* match token */ static int _tok_match(const char *str, const char *b, const char *e) { - while (*str && (b != e)) { - if (*str++ != *b++) + while (b < e) { + if (!*str || + (*str != *b)) return 0; + ++str; + ++b; } - return !(*str || (b != e)); + return !*str; /* token is matching for \0 end */ } struct dm_config_tree *dm_config_create(void)