git: 68ec84dc1bb6 - stable/13 - tree(3): allow the compare function to return any signed type
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 15 Sep 2022 16:59:21 UTC
The branch stable/13 has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=68ec84dc1bb6a7a26120d44c07825f4e8341e9b9 commit 68ec84dc1bb6a7a26120d44c07825f4e8341e9b9 Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2022-07-07 05:19:08 +0000 Commit: Doug Moore <dougm@FreeBSD.org> CommitDate: 2022-09-15 16:58:06 +0000 tree(3): allow the compare function to return any signed type This allows to write very short comparison function when we are comparing just pointer values: return ((intptr_t)((uintptr_t)a->ptr/2 - (uintptr_t)b->ptr/2)); Reviewed by: dougm, alc Differential revision: https://reviews.freebsd.org/D35722 (cherry picked from commit 86cdadbed44ecd36469dfbc4f1e492dfe51fcd4e) --- sys/sys/tree.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/sys/tree.h b/sys/sys/tree.h index db5de3b8ec87..1f0a260e25a7 100644 --- a/sys/sys/tree.h +++ b/sys/sys/tree.h @@ -176,7 +176,7 @@ name##_SPLAY_INSERT(struct name *head, struct type *elm) \ if (SPLAY_EMPTY(head)) { \ SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ } else { \ - int __comp; \ + __typeof(cmp(NULL, NULL)) __comp; \ name##_SPLAY(head, elm); \ __comp = (cmp)(elm, (head)->sph_root); \ if(__comp < 0) { \ @@ -219,7 +219,7 @@ void \ name##_SPLAY(struct name *head, struct type *elm) \ { \ struct type __node, *__left, *__right, *__tmp; \ - int __comp; \ + __typeof(cmp(NULL, NULL)) __comp; \ \ SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ __left = __right = &__node; \ @@ -729,7 +729,7 @@ name##_RB_INSERT(struct name *head, struct type *elm) \ { \ struct type *tmp; \ struct type *parent = NULL; \ - int comp = 0; \ + __typeof(cmp(NULL, NULL)) comp = 0; \ tmp = RB_ROOT(head); \ while (tmp) { \ parent = tmp; \ @@ -759,7 +759,7 @@ attr struct type * \ name##_RB_FIND(struct name *head, struct type *elm) \ { \ struct type *tmp = RB_ROOT(head); \ - int comp; \ + __typeof(cmp(NULL, NULL)) comp; \ while (tmp) { \ comp = cmp(elm, tmp); \ if (comp < 0) \ @@ -779,7 +779,7 @@ name##_RB_NFIND(struct name *head, struct type *elm) \ { \ struct type *tmp = RB_ROOT(head); \ struct type *res = NULL; \ - int comp; \ + __typeof(cmp(NULL, NULL)) comp; \ while (tmp) { \ comp = cmp(elm, tmp); \ if (comp < 0) { \