[Tarantool-patches] [PATCH 1/2] util: move cmp_i64 from xlog.c to util.h

Serge Petrenko sergepetrenko at tarantool.org
Sun Jul 5 00:55:48 MSK 2020


The comparator will be needed in other files too, e.g. box.cc

Prerequisite #4849
---
 src/box/xlog.c    | 10 +---------
 src/trivia/util.h | 11 +++++++++++
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/box/xlog.c b/src/box/xlog.c
index b5b082a20..05f8c2e29 100644
--- a/src/box/xlog.c
+++ b/src/box/xlog.c
@@ -46,6 +46,7 @@
 #include "xrow.h"
 #include "iproto_constants.h"
 #include "errinj.h"
+#include "trivia/util.h"
 
 /*
  * FALLOC_FL_KEEP_SIZE flag has existed since fallocate() was
@@ -475,15 +476,6 @@ xdir_open_cursor(struct xdir *dir, int64_t signature,
 	return 0;
 }
 
-static int
-cmp_i64(const void *_a, const void *_b)
-{
-	const int64_t *a = (const int64_t *) _a, *b = (const int64_t *) _b;
-	if (*a == *b)
-		return 0;
-	return (*a > *b) ? 1 : -1;
-}
-
 /**
  * Scan (or rescan) a directory with snapshot or write ahead logs.
  * Read all files matching a pattern from the directory -
diff --git a/src/trivia/util.h b/src/trivia/util.h
index 29c7f0194..b344af303 100644
--- a/src/trivia/util.h
+++ b/src/trivia/util.h
@@ -534,6 +534,17 @@ double_compare_int64(double lhs, int64_t rhs, int k)
 	return double_compare_nint64(lhs, rhs, k);
 }
 
+/**
+ * Compare two operands as int64_t.
+ * Needed for qsort.
+ */
+static inline int
+cmp_i64(const void *_a, const void *_b)
+{
+	const int64_t *a = (const int64_t *) _a, *b = (const int64_t *) _b;
+	return COMPARE_RESULT(*a, *b);
+}
+
 /**
  * Put the current thread in sleep for the given number of
  * seconds.
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list