From: Volker Lendecke Date: Wed, 28 Aug 2024 10:08:57 +0000 (+0200) Subject: libndr: Simplify ndr_token_retrieve_cmp_fn() X-Git-Tag: tdb-1.4.13~1260 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f43ae1ab1a8803d8c5ad4e5f3dad63ccbe91aa54;p=thirdparty%2Fsamba.git libndr: Simplify ndr_token_retrieve_cmp_fn() Avoid an if-statement inside by passing a pointer-comparing function Signed-off-by: Volker Lendecke Reviewed-by: Jennifer Sutton --- diff --git a/librpc/ndr/ndr.c b/librpc/ndr/ndr.c index 9e538f68267..75b6f67f3f3 100644 --- a/librpc/ndr/ndr.c +++ b/librpc/ndr/ndr.c @@ -1051,17 +1051,9 @@ _PUBLIC_ enum ndr_err_code ndr_token_retrieve_cmp_fn(struct ndr_token_list *list { struct ndr_token *tokens = list->tokens; unsigned i; - if (_cmp_fn) { - for (i = list->count - 1; i < list->count; i--) { - if (_cmp_fn(tokens[i].key, key) == 0) { - goto found; - } - } - } else { - for (i = list->count - 1; i < list->count; i--) { - if (tokens[i].key == key) { - goto found; - } + for (i = list->count - 1; i < list->count; i--) { + if (_cmp_fn(tokens[i].key, key) == 0) { + goto found; } } return NDR_ERR_TOKEN; @@ -1076,13 +1068,18 @@ found: return NDR_ERR_SUCCESS; } +static int token_cmp_ptr(const void *a, const void *b) +{ + return (a == b) ? 0 : 1; +} + /* retrieve a token from a ndr context */ _PUBLIC_ enum ndr_err_code ndr_token_retrieve(struct ndr_token_list *list, const void *key, uint32_t *v) { - return ndr_token_retrieve_cmp_fn(list, key, v, NULL, true); + return ndr_token_retrieve_cmp_fn(list, key, v, token_cmp_ptr, true); } /* @@ -1091,7 +1088,7 @@ _PUBLIC_ enum ndr_err_code ndr_token_retrieve(struct ndr_token_list *list, _PUBLIC_ enum ndr_err_code ndr_token_peek(struct ndr_token_list *list, const void *key, uint32_t *v) { - return ndr_token_retrieve_cmp_fn(list, key, v, NULL, false); + return ndr_token_retrieve_cmp_fn(list, key, v, token_cmp_ptr, false); } /*