From ccc4d23e749edc5ea461261427a0ee0a663fdfe5 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 22 Jul 2012 17:42:36 -0700 Subject: [PATCH] Leave extra space when creating a fake page Minimizes the number of memcpy's if additional dups are stored. --- libraries/libmdb/mdb.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index 21fa977..be009ce 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -4321,6 +4321,7 @@ more: if (mc->mc_db->md_flags & MDB_DUPFIXED) { fp->mp_flags |= P_LEAF2; fp->mp_pad = data->mv_size; + fp->mp_upper += 2 * data->mv_size; /* leave space for 2 more */ } else { fp->mp_upper += 2 * sizeof(indx_t) + 2 * NODESIZE + (dkey.mv_size & 1) + (data->mv_size & 1); @@ -4341,6 +4342,7 @@ more: fp = NODEDATA(leaf); if (flags == MDB_CURRENT) { +reuse: fp->mp_flags |= P_DIRTY; COPY_PGNO(fp->mp_pgno, mc->mc_pg[mc->mc_top]->mp_pgno); mc->mc_xcursor->mx_cursor.mc_pg[0] = fp; @@ -4349,6 +4351,9 @@ more: } if (mc->mc_db->md_flags & MDB_DUPFIXED) { offset = fp->mp_pad; + if (SIZELEFT(fp) >= offset) + goto reuse; + offset *= 4; /* space for 4 more */ } else { offset = NODESIZE + sizeof(indx_t) + data->mv_size; }