From: Hallvard Furuseth Date: Sat, 16 Aug 2014 09:34:44 +0000 (+0200) Subject: Split out mdb_midl_xmerge, add MDB_IDL_ALLOCLEN X-Git-Tag: OPENLDAP_REL_ENG_2_4_40~44^2~2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=983f896aa77027bfc88d9303d2412c58a5a1f2b4;p=openldap Split out mdb_midl_xmerge, add MDB_IDL_ALLOCLEN --- diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 47a503636c..4e23888044 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -1940,7 +1940,7 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp) MDB_txn *txn = mc->mc_txn; MDB_env *env = txn->mt_env; pgno_t pgno, *mop = env->me_pghead; - unsigned i, j, k, mop_len = mop ? mop[0] : 0, n2 = num-1; + unsigned i, j, mop_len = mop ? mop[0] : 0, n2 = num-1; MDB_page *np; txnid_t oldest = 0, last; MDB_cursor_op op; @@ -1967,7 +1967,7 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp) for (op = MDB_FIRST;; op = MDB_NEXT) { MDB_val key, data; MDB_node *leaf; - pgno_t *idl, old_id, new_id; + pgno_t *idl; /* Seek a big enough contiguous page range. Prefer * pages at the tail, just truncating the list. @@ -2033,21 +2033,12 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp) #if (MDB_DEBUG) > 1 DPRINTF(("IDL read txn %"Z"u root %"Z"u num %u", last, txn->mt_dbs[FREE_DBI].md_root, i)); - for (k = i; k; k--) - DPRINTF(("IDL %"Z"u", idl[k])); + for (j = i; j; j--) + DPRINTF(("IDL %"Z"u", idl[j])); #endif /* Merge in descending sorted order */ - j = mop_len; - k = mop_len += i; - mop[0] = (pgno_t)-1; - old_id = mop[j]; - while (i) { - new_id = idl[i--]; - for (; old_id < new_id; old_id = mop[--j]) - mop[k--] = old_id; - mop[k--] = new_id; - } - mop[0] = mop_len; + mdb_midl_xmerge(mop, idl); + mop_len = mop[0]; } /* Use new pages from the map when nothing suitable in the freeDB */ diff --git a/libraries/liblmdb/midl.c b/libraries/liblmdb/midl.c index d3d872a29b..88a3aff10c 100644 --- a/libraries/liblmdb/midl.c +++ b/libraries/liblmdb/midl.c @@ -199,6 +199,20 @@ int mdb_midl_append_range( MDB_IDL *idp, MDB_ID id, unsigned n ) return 0; } +void mdb_midl_xmerge( MDB_IDL idl, MDB_IDL merge ) +{ + MDB_ID old_id, merge_id, i = merge[0], j = idl[0], k = i+j, total = k; + idl[0] = (MDB_ID)-1; /* delimiter for idl scan below */ + old_id = idl[j]; + while (i) { + merge_id = merge[i--]; + for (; old_id < merge_id; old_id = idl[--j]) + idl[k--] = old_id; + idl[k--] = merge_id; + } + idl[0] = total; +} + /* Quicksort + Insertion sort for small arrays */ #define SMALL 8 diff --git a/libraries/liblmdb/midl.h b/libraries/liblmdb/midl.h index 08616f452e..a7f25026ce 100644 --- a/libraries/liblmdb/midl.h +++ b/libraries/liblmdb/midl.h @@ -68,6 +68,9 @@ typedef MDB_ID *MDB_IDL; #define MDB_IDL_FIRST( ids ) ( (ids)[1] ) #define MDB_IDL_LAST( ids ) ( (ids)[(ids)[0]] ) + /** Current max length of an #mdb_midl_alloc()ed IDL */ +#define MDB_IDL_ALLOCLEN( ids ) ( (ids)[-1] ) + /** Append ID to IDL. The IDL must be big enough. */ #define mdb_midl_xappend(idl, id) do { \ MDB_ID *xidl = (idl), xlen = ++(xidl[0]); \ @@ -128,6 +131,12 @@ int mdb_midl_append_list( MDB_IDL *idp, MDB_IDL app ); */ int mdb_midl_append_range( MDB_IDL *idp, MDB_ID id, unsigned n ); + /** Merge an IDL onto an IDL. The destination IDL must be big enough. + * @param[in] idl The IDL to merge into. + * @param[in] merge The IDL to merge. + */ +void mdb_midl_xmerge( MDB_IDL idl, MDB_IDL merge ); + /** Sort an IDL. * @param[in,out] ids The IDL to sort. */