mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 11:29:19 +08:00
mdbx: alter mdbx_node_shrink().
This commit is contained in:
parent
ecb0e268b0
commit
a30828b457
12
src/mdbx.c
12
src/mdbx.c
@ -8889,19 +8889,23 @@ static void mdbx_node_shrink(MDBX_page *mp, unsigned indx) {
|
|||||||
node = NODEPTR(mp, indx);
|
node = NODEPTR(mp, indx);
|
||||||
sp = (MDBX_page *)NODEDATA(node);
|
sp = (MDBX_page *)NODEDATA(node);
|
||||||
delta = SIZELEFT(sp);
|
delta = SIZELEFT(sp);
|
||||||
nsize = NODEDSZ(node) - delta;
|
assert(delta > 0);
|
||||||
|
|
||||||
/* Prepare to shift upward, set len = length(subpage part to shift) */
|
/* Prepare to shift upward, set len = length(subpage part to shift) */
|
||||||
if (IS_LEAF2(sp)) {
|
if (unlikely(IS_LEAF2(sp))) {
|
||||||
|
delta &= /* do not make the node uneven-sized */ ~1u;
|
||||||
|
if (unlikely(delta) == 0)
|
||||||
|
return;
|
||||||
|
nsize = NODEDSZ(node) - delta;
|
||||||
|
assert(nsize % 1 == 0);
|
||||||
len = nsize;
|
len = nsize;
|
||||||
if (nsize & 1)
|
|
||||||
return; /* do not make the node uneven-sized */
|
|
||||||
} else {
|
} else {
|
||||||
xp = (MDBX_page *)((char *)sp + delta); /* destination subpage */
|
xp = (MDBX_page *)((char *)sp + delta); /* destination subpage */
|
||||||
for (i = NUMKEYS(sp); --i >= 0;) {
|
for (i = NUMKEYS(sp); --i >= 0;) {
|
||||||
assert(sp->mp_ptrs[i] >= delta);
|
assert(sp->mp_ptrs[i] >= delta);
|
||||||
xp->mp_ptrs[i] = (indx_t)(sp->mp_ptrs[i] - delta);
|
xp->mp_ptrs[i] = (indx_t)(sp->mp_ptrs[i] - delta);
|
||||||
}
|
}
|
||||||
|
nsize = NODEDSZ(node) - delta;
|
||||||
len = PAGEHDRSZ;
|
len = PAGEHDRSZ;
|
||||||
}
|
}
|
||||||
sp->mp_upper = sp->mp_lower;
|
sp->mp_upper = sp->mp_lower;
|
||||||
|
Loading…
Reference in New Issue
Block a user