From 3dfe8e10dfdd6e12b95a901d1ec8d60f44542c2e Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 29 Dec 2016 16:01:51 -0800 Subject: [PATCH] Add little cmp u64 helper We have use of this little u64 comparison function in a few more places so let's make it a proper usable inline function in a header. Signed-off-by: Zach Brown --- kmod/src/cmp.h | 11 +++++++++++ kmod/src/seg.c | 10 +++------- 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 kmod/src/cmp.h diff --git a/kmod/src/cmp.h b/kmod/src/cmp.h new file mode 100644 index 00000000..3230c043 --- /dev/null +++ b/kmod/src/cmp.h @@ -0,0 +1,11 @@ +#ifndef _SCOUTFS_CMP_H_ +#define _SCOUTFS_CMP_H_ + +#include + +static inline int scoutfs_cmp_u64s(u64 a, u64 b) +{ + return a < b ? -1 : a > b ? 1 : 0; +} + +#endif diff --git a/kmod/src/seg.c b/kmod/src/seg.c index d4eeb32f..37277096 100644 --- a/kmod/src/seg.c +++ b/kmod/src/seg.c @@ -21,6 +21,7 @@ #include "seg.h" #include "bio.h" #include "kvec.h" +#include "cmp.h" #include "manifest.h" #include "alloc.h" @@ -99,11 +100,6 @@ void scoutfs_seg_put(struct scoutfs_segment *seg) } } -static int cmp_u64s(u64 a, u64 b) -{ - return a < b ? -1 : a > b ? 1 : 0; -} - static struct scoutfs_segment *find_seg(struct rb_root *root, u64 segno) { struct rb_node *node = root->rb_node; @@ -115,7 +111,7 @@ static struct scoutfs_segment *find_seg(struct rb_root *root, u64 segno) parent = node; seg = container_of(node, struct scoutfs_segment, node); - cmp = cmp_u64s(segno, seg->segno); + cmp = scoutfs_cmp_u64s(segno, seg->segno); if (cmp < 0) node = node->rb_left; else if (cmp > 0) @@ -146,7 +142,7 @@ static struct scoutfs_segment *replace_seg(struct rb_root *root, parent = *node; seg = container_of(*node, struct scoutfs_segment, node); - cmp = cmp_u64s(ins->segno, seg->segno); + cmp = scoutfs_cmp_u64s(ins->segno, seg->segno); if (cmp < 0) { node = &(*node)->rb_left; } else if (cmp > 0) {