mdbx: refine/simplify MDBX_node.

Change-Id: Idb3843727a409c3ef8d1d54e226a6f578a57c32e
This commit is contained in:
Leonid Yuriev 2019-10-04 01:51:19 +03:00
parent daddd53793
commit 8768641872
2 changed files with 21 additions and 25 deletions

View File

@ -59,7 +59,7 @@ static __inline unsigned mdbx_log2(size_t value) {
}
/* Address of node i in page p */
static __inline MDBX_node *NODEPTR(MDBX_page *p, unsigned i) {
static __inline MDBX_node *NODEPTR(const MDBX_page *p, unsigned i) {
assert(NUMKEYS(p) > (unsigned)(i));
return (MDBX_node *)((char *)(p) + (p)->mp_ptrs[i] + PAGEHDRSZ);
}
@ -68,7 +68,7 @@ static __inline MDBX_node *NODEPTR(MDBX_page *p, unsigned i) {
static __inline pgno_t NODEPGNO(const MDBX_node *node) {
pgno_t pgno;
if (MDBX_UNALIGNED_OK) {
pgno = node->mn_ksize_and_pgno;
pgno = node->mn_pgno32;
if (sizeof(pgno_t) > 4)
pgno &= MAX_PAGENO;
} else {
@ -85,13 +85,13 @@ static __inline void SETPGNO(MDBX_node *node, pgno_t pgno) {
if (MDBX_UNALIGNED_OK) {
if (sizeof(pgno_t) > 4)
pgno |= ((uint64_t)node->mn_ksize) << 48;
node->mn_ksize_and_pgno = pgno;
pgno |= ((uint64_t)node->mn_ksize) << 32;
node->mn_pgno32 = pgno;
} else {
node->mn_lo = (uint16_t)pgno;
node->mn_hi = (uint16_t)(pgno >> 16);
if (sizeof(pgno_t) > 4)
node->mn_flags = (uint16_t)((uint64_t)pgno >> 32);
node->mn_ksize = (uint16_t)((uint64_t)pgno >> 32);
}
}

View File

@ -1243,30 +1243,26 @@ MDBX_INTERNAL_FUNC void mdbx_rthc_thread_dtor(void *ptr);
* F_DUPDATA and F_SUBDATA can be combined giving duplicate data in
* a sub-page/sub-database, and named databases (just F_SUBDATA). */
typedef struct MDBX_node {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
union {
struct {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
union {
struct {
uint16_t mn_lo, mn_hi; /* part of data size or pgno */
};
uint32_t mn_dsize;
};
uint16_t mn_flags; /* see mdbx_node */
uint16_t mn_ksize; /* key size */
#else
uint16_t mn_ksize; /* key size */
uint16_t mn_flags; /* see mdbx_node */
union {
struct {
uint16_t mn_hi, mn_lo; /* part of data size or pgno */
};
uint32_t mn_dsize;
};
#endif
uint16_t mn_lo, mn_hi; /* part of data size or pgno */
};
pgno_t mn_ksize_and_pgno;
uint32_t mn_dsize;
uint32_t mn_pgno32;
};
uint16_t mn_flags; /* see mdbx_node */
uint16_t mn_ksize; /* key size */
#else
uint16_t mn_ksize; /* key size */
uint16_t mn_flags; /* see mdbx_node */
union {
struct {
uint16_t mn_hi, mn_lo; /* part of data size or pgno */
};
uint32_t mn_dsize;
};
#endif
/* mdbx_node Flags */
#define F_BIGDATA 0x01 /* data put on overflow page */