From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp29.i.mail.ru (smtp29.i.mail.ru [94.100.177.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 91E7542F4AE for ; Sun, 5 Jul 2020 00:56:07 +0300 (MSK) From: Serge Petrenko Date: Sun, 5 Jul 2020 00:55:48 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/2] util: move cmp_i64 from xlog.c to util.h List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, gorcunov@gmail.com, sergos@tarantool.org Cc: tarantool-patches@dev.tarantool.org 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)