]> git.sur5r.net Git - openldap/commitdiff
Simpler mdb_node_add()
authorHallvard Furuseth <hallvard@openldap.org>
Sat, 11 Jul 2015 19:09:36 +0000 (21:09 +0200)
committerHallvard Furuseth <hallvard@openldap.org>
Sun, 25 Oct 2015 09:55:22 +0000 (10:55 +0100)
libraries/liblmdb/mdb.c

index 5f0cf63ec019dace95433f0c84dc17ac67b05cc3..2d8d0567ad62a99f053dfaa44f62c7b467ddfc1d 100644 (file)
@@ -6924,6 +6924,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);
@@ -6954,7 +6955,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);
@@ -7005,23 +7006,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 = METADATA(ofp);
                        if (F_ISSET(flags, MDB_RESERVE))
-                               data->mv_data = METADATA(ofp);
+                               data->mv_data = ndata;
                        else
-                               memcpy(METADATA(ofp), data->mv_data, data->mv_size);
+                               memcpy(ndata, data->mv_data, data->mv_size);
                }
        }