mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-06 19:04:12 +08:00
mdbx: minor refactoring cursor_put()
.
Change-Id: Iacdc02f70278382bf0e7fb496bb57f4010403dd0
This commit is contained in:
parent
7cbd500534
commit
760cf515a7
51
src/core.c
51
src/core.c
@ -14185,7 +14185,7 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data,
|
|||||||
MDBX_page *sub_root = NULL;
|
MDBX_page *sub_root = NULL;
|
||||||
MDBX_val xdata, *rdata, dkey, olddata;
|
MDBX_val xdata, *rdata, dkey, olddata;
|
||||||
MDBX_db nested_dupdb;
|
MDBX_db nested_dupdb;
|
||||||
int rc2;
|
int err;
|
||||||
DKBUF_DEBUG;
|
DKBUF_DEBUG;
|
||||||
|
|
||||||
if (unlikely(mc == NULL || key == NULL || data == NULL))
|
if (unlikely(mc == NULL || key == NULL || data == NULL))
|
||||||
@ -14440,23 +14440,22 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data,
|
|||||||
|
|
||||||
/* Cursor is positioned, check for room in the dirty list */
|
/* Cursor is positioned, check for room in the dirty list */
|
||||||
if (!nospill) {
|
if (!nospill) {
|
||||||
|
rdata = data;
|
||||||
if (unlikely(flags & MDBX_MULTIPLE)) {
|
if (unlikely(flags & MDBX_MULTIPLE)) {
|
||||||
rdata = &xdata;
|
rdata = &xdata;
|
||||||
xdata.iov_len = data->iov_len * dcount;
|
xdata.iov_len = data->iov_len * dcount;
|
||||||
} else {
|
|
||||||
rdata = data;
|
|
||||||
}
|
}
|
||||||
if (unlikely(rc2 = mdbx_cursor_spill(mc, key, rdata)))
|
if (unlikely(err = mdbx_cursor_spill(mc, key, rdata)))
|
||||||
return rc2;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(rc == MDBX_NO_ROOT)) {
|
if (unlikely(rc == MDBX_NO_ROOT)) {
|
||||||
/* new database, write a root leaf page */
|
/* new database, write a root leaf page */
|
||||||
mdbx_debug("%s", "allocating new root leaf page");
|
mdbx_debug("%s", "allocating new root leaf page");
|
||||||
if (unlikely((*mc->mc_dbistate & DBI_DIRTY) == 0)) {
|
if (unlikely((*mc->mc_dbistate & DBI_DIRTY) == 0)) {
|
||||||
rc2 = mdbx_touch_dbi(mc);
|
err = mdbx_touch_dbi(mc);
|
||||||
if (unlikely(rc2 != MDBX_SUCCESS))
|
if (unlikely(err != MDBX_SUCCESS))
|
||||||
return rc2;
|
return err;
|
||||||
}
|
}
|
||||||
struct page_result npr = mdbx_page_new(mc, P_LEAF, 1);
|
struct page_result npr = mdbx_page_new(mc, P_LEAF, 1);
|
||||||
if (unlikely(npr.err != MDBX_SUCCESS))
|
if (unlikely(npr.err != MDBX_SUCCESS))
|
||||||
@ -14486,9 +14485,9 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data,
|
|||||||
mc->mc_flags |= C_INITIALIZED;
|
mc->mc_flags |= C_INITIALIZED;
|
||||||
} else {
|
} else {
|
||||||
/* make sure all cursor pages are writable */
|
/* make sure all cursor pages are writable */
|
||||||
rc2 = mdbx_cursor_touch(mc);
|
err = mdbx_cursor_touch(mc);
|
||||||
if (unlikely(rc2))
|
if (unlikely(err))
|
||||||
return rc2;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool insert_key, insert_data, do_sub = false;
|
bool insert_key, insert_data, do_sub = false;
|
||||||
@ -14529,13 +14528,13 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data,
|
|||||||
mc->mc_top--;
|
mc->mc_top--;
|
||||||
dtop++;
|
dtop++;
|
||||||
}
|
}
|
||||||
rc2 = MDBX_SUCCESS;
|
err = MDBX_SUCCESS;
|
||||||
if (mc->mc_ki[mc->mc_top])
|
if (mc->mc_ki[mc->mc_top])
|
||||||
rc2 = mdbx_update_key(mc, key);
|
err = mdbx_update_key(mc, key);
|
||||||
mdbx_cassert(mc, mc->mc_top + dtop < UINT16_MAX);
|
mdbx_cassert(mc, mc->mc_top + dtop < UINT16_MAX);
|
||||||
mc->mc_top += (uint16_t)dtop;
|
mc->mc_top += (uint16_t)dtop;
|
||||||
if (unlikely(rc2 != MDBX_SUCCESS))
|
if (unlikely(err != MDBX_SUCCESS))
|
||||||
return rc2;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mdbx_audit_enabled()) {
|
if (mdbx_audit_enabled()) {
|
||||||
@ -14594,9 +14593,9 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data,
|
|||||||
return MDBX_ENOMEM;
|
return MDBX_ENOMEM;
|
||||||
|
|
||||||
memcpy(np, pgr.page, PAGEHDRSZ); /* Copy header of page */
|
memcpy(np, pgr.page, PAGEHDRSZ); /* Copy header of page */
|
||||||
rc2 = mdbx_page_dirty(mc->mc_txn, pgr.page = np, ovpages);
|
err = mdbx_page_dirty(mc->mc_txn, pgr.page = np, ovpages);
|
||||||
if (unlikely(rc2 != MDBX_SUCCESS))
|
if (unlikely(err != MDBX_SUCCESS))
|
||||||
return rc2;
|
return err;
|
||||||
|
|
||||||
#if MDBX_ENABLE_PGOP_STAT
|
#if MDBX_ENABLE_PGOP_STAT
|
||||||
safe64_inc(&mc->mc_txn->mt_env->me_pgop_stat->clone, ovpages);
|
safe64_inc(&mc->mc_txn->mt_env->me_pgop_stat->clone, ovpages);
|
||||||
@ -14618,8 +14617,8 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data,
|
|||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc2 = mdbx_page_retire(mc, pgr.page)) != MDBX_SUCCESS)
|
if ((err = mdbx_page_retire(mc, pgr.page)) != MDBX_SUCCESS)
|
||||||
return rc2;
|
return err;
|
||||||
} else {
|
} else {
|
||||||
olddata.iov_len = node_ds(node);
|
olddata.iov_len = node_ds(node);
|
||||||
olddata.iov_base = node_data(node);
|
olddata.iov_base = node_data(node);
|
||||||
@ -14882,9 +14881,9 @@ new_sub:;
|
|||||||
SHIFT_MDBX_NODUPDATA_TO_MDBX_NOOVERWRITE);
|
SHIFT_MDBX_NODUPDATA_TO_MDBX_NOOVERWRITE);
|
||||||
if ((flags & MDBX_CURRENT) == 0) {
|
if ((flags & MDBX_CURRENT) == 0) {
|
||||||
xflags -= MDBX_CURRENT;
|
xflags -= MDBX_CURRENT;
|
||||||
rc2 = mdbx_xcursor_init1(mc, node, mc->mc_pg[mc->mc_top]);
|
err = mdbx_xcursor_init1(mc, node, mc->mc_pg[mc->mc_top]);
|
||||||
if (unlikely(rc2 != MDBX_SUCCESS))
|
if (unlikely(err != MDBX_SUCCESS))
|
||||||
return rc2;
|
return err;
|
||||||
}
|
}
|
||||||
if (sub_root)
|
if (sub_root)
|
||||||
mc->mc_xcursor->mx_cursor.mc_pg[0] = sub_root;
|
mc->mc_xcursor->mx_cursor.mc_pg[0] = sub_root;
|
||||||
@ -14911,9 +14910,9 @@ new_sub:;
|
|||||||
continue;
|
continue;
|
||||||
if (m2->mc_pg[i] == mp) {
|
if (m2->mc_pg[i] == mp) {
|
||||||
if (m2->mc_ki[i] == mc->mc_ki[i]) {
|
if (m2->mc_ki[i] == mc->mc_ki[i]) {
|
||||||
rc2 = mdbx_xcursor_init2(m2, mx, dupdata_flag);
|
err = mdbx_xcursor_init2(m2, mx, dupdata_flag);
|
||||||
if (unlikely(rc2 != MDBX_SUCCESS))
|
if (unlikely(err != MDBX_SUCCESS))
|
||||||
return rc2;
|
return err;
|
||||||
} else if (!insert_key && m2->mc_ki[i] < nkeys) {
|
} else if (!insert_key && m2->mc_ki[i] < nkeys) {
|
||||||
XCURSOR_REFRESH(m2, mp, m2->mc_ki[i]);
|
XCURSOR_REFRESH(m2, mp, m2->mc_ki[i]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user