mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-21 18:28:20 +08:00
lmdb, back-mdb: use 'long' as result to speedup comparison.
Change-Id: I3ade0c7525f4a461a7edf5873af196e6b33c0727
This commit is contained in:
parent
e2127a6e57
commit
c32cf0fea4
2
lmdb.h
2
lmdb.h
@ -240,7 +240,7 @@ typedef struct MDB_val {
|
|||||||
} MDB_val;
|
} MDB_val;
|
||||||
|
|
||||||
/** @brief A callback function used to compare two keys in a database */
|
/** @brief A callback function used to compare two keys in a database */
|
||||||
typedef int (MDB_cmp_func)(const MDB_val *a, const MDB_val *b);
|
typedef long (MDB_cmp_func)(const MDB_val *a, const MDB_val *b);
|
||||||
|
|
||||||
/** @brief A callback function used to relocate a position-dependent data item
|
/** @brief A callback function used to relocate a position-dependent data item
|
||||||
* in a fixed-address database.
|
* in a fixed-address database.
|
||||||
|
35
mdb.c
35
mdb.c
@ -4819,24 +4819,22 @@ mdb_env_close_ex(MDB_env *env, int dont_sync)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compare two items pointing at aligned unsigned int's. */
|
/** Compare two items pointing at aligned unsigned int's. */
|
||||||
static int
|
static long
|
||||||
mdb_cmp_int_ai(const MDB_val *a, const MDB_val *b)
|
mdb_cmp_int_ai(const MDB_val *a, const MDB_val *b)
|
||||||
{
|
{
|
||||||
mdb_assert(NULL, a->mv_size == b->mv_size);
|
mdb_assert(NULL, a->mv_size == b->mv_size);
|
||||||
mdb_assert(NULL, 0 == (uintptr_t) a->mv_data % sizeof(int)
|
mdb_assert(NULL, 0 == (uintptr_t) a->mv_data % sizeof(int)
|
||||||
&& 0 == (uintptr_t) b->mv_data % sizeof(int));
|
&& 0 == (uintptr_t) b->mv_data % sizeof(int));
|
||||||
|
|
||||||
if (sizeof(int) != sizeof(size_t) && likely(a->mv_size == sizeof(size_t))) {
|
if (sizeof(int) != sizeof(long) && likely(a->mv_size == sizeof(long)))
|
||||||
return (*(size_t *)a->mv_data < *(size_t *)b->mv_data) ? -1 :
|
return *(long *)a->mv_data - *(long *)b->mv_data;
|
||||||
*(size_t *)a->mv_data > *(size_t *)b->mv_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
mdb_assert(NULL, a->mv_size == sizeof(int) );
|
mdb_assert(NULL, a->mv_size == sizeof(int) );
|
||||||
return *(int *)a->mv_data - *(int *)b->mv_data;
|
return *(int *)a->mv_data - *(int *)b->mv_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compare two items pointing at 2-byte aligned unsigned int's. */
|
/** Compare two items pointing at 2-byte aligned unsigned int's. */
|
||||||
static int
|
static long
|
||||||
mdb_cmp_int_a2(const MDB_val *a, const MDB_val *b)
|
mdb_cmp_int_a2(const MDB_val *a, const MDB_val *b)
|
||||||
{
|
{
|
||||||
mdb_assert(NULL, a->mv_size == b->mv_size);
|
mdb_assert(NULL, a->mv_size == b->mv_size);
|
||||||
@ -4844,16 +4842,14 @@ mdb_cmp_int_a2(const MDB_val *a, const MDB_val *b)
|
|||||||
mdb_assert(NULL, 0 == (uintptr_t) a->mv_data % sizeof(short)
|
mdb_assert(NULL, 0 == (uintptr_t) a->mv_data % sizeof(short)
|
||||||
&& 0 == (uintptr_t) b->mv_data % sizeof(short));
|
&& 0 == (uintptr_t) b->mv_data % sizeof(short));
|
||||||
#ifdef MISALIGNED_OK
|
#ifdef MISALIGNED_OK
|
||||||
if (sizeof(int) != sizeof(size_t) && likely(a->mv_size == sizeof(size_t))) {
|
if (sizeof(int) != sizeof(long) && likely(a->mv_size == sizeof(long)))
|
||||||
return (*(size_t *)a->mv_data < *(size_t *)b->mv_data) ? -1 :
|
return *(long *)a->mv_data - *(long *)b->mv_data;
|
||||||
*(size_t *)a->mv_data > *(size_t *)b->mv_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
mdb_assert(NULL, a->mv_size == sizeof(int) );
|
mdb_assert(NULL, a->mv_size == sizeof(int) );
|
||||||
return *(int *)a->mv_data - *(int *)b->mv_data;
|
return *(int *)a->mv_data - *(int *)b->mv_data;
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
int x;
|
long x;
|
||||||
unsigned short *u, *c;
|
unsigned short *u, *c;
|
||||||
|
|
||||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
@ -4881,14 +4877,13 @@ mdb_cmp_int_a2(const MDB_val *a, const MDB_val *b)
|
|||||||
*
|
*
|
||||||
* This is also set as #MDB_INTEGERDUP|#MDB_DUPFIXED's #MDB_dbx.%md_dcmp.
|
* This is also set as #MDB_INTEGERDUP|#MDB_DUPFIXED's #MDB_dbx.%md_dcmp.
|
||||||
*/
|
*/
|
||||||
static int
|
static long
|
||||||
mdb_cmp_int_ua(const MDB_val *a, const MDB_val *b)
|
mdb_cmp_int_ua(const MDB_val *a, const MDB_val *b)
|
||||||
{
|
{
|
||||||
mdb_assert(NULL, a->mv_size == b->mv_size);
|
mdb_assert(NULL, a->mv_size == b->mv_size);
|
||||||
#if MISALIGNED_OK
|
#if MISALIGNED_OK
|
||||||
if (sizeof(int) != sizeof(size_t) && likely(a->mv_size == sizeof(size_t)))
|
if (sizeof(int) != sizeof(long) && likely(a->mv_size == sizeof(long)))
|
||||||
return (*(size_t *)a->mv_data < *(size_t *)b->mv_data) ? -1 :
|
return *(long *)a->mv_data - *(long *)b->mv_data;
|
||||||
*(size_t *)a->mv_data > *(size_t *)b->mv_data;
|
|
||||||
|
|
||||||
mdb_assert(NULL, a->mv_size == sizeof(int) );
|
mdb_assert(NULL, a->mv_size == sizeof(int) );
|
||||||
return *(int *)a->mv_data - *(int *)b->mv_data;
|
return *(int *)a->mv_data - *(int *)b->mv_data;
|
||||||
@ -4897,7 +4892,7 @@ mdb_cmp_int_ua(const MDB_val *a, const MDB_val *b)
|
|||||||
{
|
{
|
||||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
const unsigned char *p1, *p2;
|
const unsigned char *p1, *p2;
|
||||||
int diff;
|
long diff;
|
||||||
|
|
||||||
p1 = (const unsigned char *)a->mv_data + a->mv_size;
|
p1 = (const unsigned char *)a->mv_data + a->mv_size;
|
||||||
p2 = (const unsigned char *)b->mv_data + a->mv_size;
|
p2 = (const unsigned char *)b->mv_data + a->mv_size;
|
||||||
@ -4916,10 +4911,10 @@ mdb_cmp_int_ua(const MDB_val *a, const MDB_val *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compare two items lexically */
|
/** Compare two items lexically */
|
||||||
static int
|
static long
|
||||||
mdb_cmp_memn(const MDB_val *a, const MDB_val *b)
|
mdb_cmp_memn(const MDB_val *a, const MDB_val *b)
|
||||||
{
|
{
|
||||||
int diff;
|
long diff;
|
||||||
ssize_t len_diff;
|
ssize_t len_diff;
|
||||||
unsigned len;
|
unsigned len;
|
||||||
|
|
||||||
@ -4935,12 +4930,12 @@ mdb_cmp_memn(const MDB_val *a, const MDB_val *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compare two items in reverse byte order */
|
/** Compare two items in reverse byte order */
|
||||||
static int
|
static long
|
||||||
mdb_cmp_memnr(const MDB_val *a, const MDB_val *b)
|
mdb_cmp_memnr(const MDB_val *a, const MDB_val *b)
|
||||||
{
|
{
|
||||||
const unsigned char *p1, *p2, *p1_lim;
|
const unsigned char *p1, *p2, *p1_lim;
|
||||||
ssize_t len_diff;
|
ssize_t len_diff;
|
||||||
int diff;
|
long diff;
|
||||||
|
|
||||||
p1_lim = (const unsigned char *)a->mv_data;
|
p1_lim = (const unsigned char *)a->mv_data;
|
||||||
p1 = (const unsigned char *)a->mv_data + a->mv_size;
|
p1 = (const unsigned char *)a->mv_data + a->mv_size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user