From 90aa4b154a9d0b624c6b5f66faca65d9205a3dab Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Tue, 19 Apr 2016 00:44:30 +0300 Subject: [PATCH] mdbx: refine mdbx_cmp2int(). Change-Id: I5497db2e88d764e18a1aae1809dc66fd62a5adbe --- mdb.c | 6 +++++- midl.c | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mdb.c b/mdb.c index 4c8cb226..9b7e452d 100644 --- a/mdb.c +++ b/mdb.c @@ -5136,7 +5136,11 @@ mdb_env_close(MDB_env *env) * | 1, a > b * \ */ -#define mdbx_cmp2int(a, b) (((a) > (b)) - ((b) > (a))) +#if 1 +# define mdbx_cmp2int(a, b) (((b) > (a)) ? -1 : (a) > (b)) +#else +# define mdbx_cmp2int(a, b) (((a) > (b)) - ((b) > (a))) +#endif /** Compare two items pointing at aligned unsigned int's. */ static int __hot diff --git a/midl.c b/midl.c index 5156d7a1..8fae4693 100644 --- a/midl.c +++ b/midl.c @@ -28,7 +28,6 @@ /** @defgroup idls ID List Management * @{ */ -#define CMP(x,y) ( (x) < (y) ? -1 : (x) > (y) ) static unsigned __hot mdb_midl_search( MDB_IDL ids, MDB_ID id ) @@ -46,7 +45,7 @@ mdb_midl_search( MDB_IDL ids, MDB_ID id ) while( 0 < n ) { unsigned pivot = n >> 1; cursor = base + pivot + 1; - val = CMP( ids[cursor], id ); + val = mdbx_cmp2int( ids[cursor], id ); if( val < 0 ) { n = pivot; @@ -295,7 +294,7 @@ mdb_mid2l_search( MDB_ID2L ids, MDB_ID id ) while( 0 < n ) { unsigned pivot = n >> 1; cursor = base + pivot + 1; - val = CMP( id, ids[cursor].mid ); + val = mdbx_cmp2int( id, ids[cursor].mid ); if( val < 0 ) { n = pivot;