lmdb: Simpler mdb_node_add().

Change-Id: I5b1f851a098aeb4b5adcd7ed55150a055cd63102
This commit is contained in:
Hallvard Furuseth 2015-07-11 21:09:36 +02:00 committed by Leo Yuriev
parent 2fdf96cf4f
commit 862cfc30c4

21
mdb.c
View File

@ -6849,6 +6849,7 @@ mdb_node_add(MDB_cursor *mc, indx_t indx,
MDB_node *node;
MDB_page *mp = mc->mc_pg[mc->mc_top];
MDB_page *ofp = NULL; /* overflow page */
void *ndata;
DKBUF;
mdb_cassert(mc, mp->mp_upper >= mp->mp_lower);
@ -6879,7 +6880,7 @@ mdb_node_add(MDB_cursor *mc, indx_t indx,
if (key != NULL)
node_size += key->mv_size;
if (IS_LEAF(mp)) {
mdb_cassert(mc, data);
mdb_cassert(mc, key && data);
if (F_ISSET(flags, F_BIGDATA)) {
/* Data already on overflow page. */
node_size += sizeof(pgno_t);
@ -6930,23 +6931,21 @@ update:
memcpy(NODEKEY(node), key->mv_data, key->mv_size);
if (IS_LEAF(mp)) {
mdb_cassert(mc, key);
ndata = NODEDATA(node);
if (ofp == NULL) {
if (F_ISSET(flags, F_BIGDATA))
memcpy(node->mn_data + key->mv_size, data->mv_data,
sizeof(pgno_t));
memcpy(ndata, data->mv_data, sizeof(pgno_t));
else if (F_ISSET(flags, MDB_RESERVE))
data->mv_data = node->mn_data + key->mv_size;
data->mv_data = ndata;
else
memcpy(node->mn_data + key->mv_size, data->mv_data,
data->mv_size);
memcpy(ndata, data->mv_data, data->mv_size);
} else {
memcpy(node->mn_data + key->mv_size, &ofp->mp_pgno,
sizeof(pgno_t));
memcpy(ndata, &ofp->mp_pgno, sizeof(pgno_t));
ndata = PAGEDATA(ofp);
if (F_ISSET(flags, MDB_RESERVE))
data->mv_data = PAGEDATA(ofp);
data->mv_data = ndata;
else
memcpy(PAGEDATA(ofp), data->mv_data, data->mv_size);
memcpy(ndata, data->mv_data, data->mv_size);
}
}