]> git.sur5r.net Git - openldap/commitdiff
Minor cleanup
authorHoward Chu <hyc@symas.com>
Mon, 5 Sep 2011 21:22:46 +0000 (14:22 -0700)
committerHoward Chu <hyc@symas.com>
Mon, 5 Sep 2011 21:22:46 +0000 (14:22 -0700)
libraries/libmdb/mdb.c
libraries/libmdb/midl.c
libraries/libmdb/midl.h

index 27f2387de22c822450876c127b952c062c9c49f8..bf09af860ce13ad8f367234a4e9f66c77aea6c66 100644 (file)
@@ -440,7 +440,7 @@ struct MDB_env {
        pthread_key_t   me_txkey;       /* thread-key for readers */
        MDB_dpage       *me_dpages;
        pgno_t          me_free_pgs[MDB_IDL_UM_SIZE];
-       ID2                     me_dirty_list[MDB_IDL_DB_SIZE];
+       ID2                     me_dirty_list[MDB_IDL_UM_SIZE];
        LAZY_RWLOCK_DEF(me_dblock);
 #ifdef _WIN32
        HANDLE          me_rmutex;              /* Windows mutexes don't reside in shared mem */
@@ -2543,11 +2543,17 @@ mdb_cursor_set(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
                }
                rc = cursor->mc_txn->mt_dbxs[cursor->mc_dbi].md_cmp(key, &nodekey);
                if (rc == 0) {
+                       /* Probably happens rarely, but first node on the page
+                        * was the one we wanted.
+                        */
+                       top->mp_ki = 0;
 set1:
-                       /* we're already on the right page */
                        mpp.mp_page = top->mp_page;
+                       if (exactp)
+                               *exactp = 1;
                        rc = 0;
-                       goto set2;
+                       leaf = NODEPTR(top->mp_page, top->mp_ki);
+                       goto set3;
                }
                if (rc > 0) {
                        unsigned int i;
@@ -2560,7 +2566,17 @@ set1:
                                        MDB_SET_KEY(leaf, &nodekey);
                                }
                                rc = cursor->mc_txn->mt_dbxs[cursor->mc_dbi].md_cmp(key, &nodekey);
-                               if (rc <= 0) goto set1;
+                               if (rc == 0) {
+                                       /* last node was the one we wanted */
+                                       top->mp_ki = NUMKEYS(top->mp_page)-1;
+                                       goto set1;
+                               }
+                               if (rc < 0) {
+                                       /* This is definitely the right page, skip search_page */
+                                       mpp.mp_page = top->mp_page;
+                                       rc = 0;
+                                       goto set2;
+                               }
                        }
                        /* If any parents have right-sibs, search.
                         * Otherwise, there's nothing further.
@@ -2571,7 +2587,8 @@ set1:
                                        break;
                        if (i == cursor->mc_snum - 1) {
                                /* There are no other pages */
-                               goto set1;
+                               top->mp_ki = NUMKEYS(top->mp_page);
+                               return MDB_NOTFOUND;
                        }
                }
        }
@@ -2603,6 +2620,7 @@ set2:
                leaf = NODEPTR(mpp.mp_page, 0);
        }
 
+set3:
        cursor->mc_flags |= C_INITIALIZED;
        cursor->mc_flags &= ~C_EOF;
 
index 17b6e51f9787e9df70c211bb50f8078f164a2dba..7932d3caeea3dfe779f757d6707243e1a9eb0cbd 100644 (file)
@@ -28,7 +28,7 @@
  */
 #define CMP(x,y)        ( (x) < (y) ? -1 : (x) > (y) )
 
-#if 0
+#if 0  /* superseded by append/sort */
 static unsigned mdb_midl_search( IDL ids, ID id )
 {
        /*
@@ -119,7 +119,7 @@ int mdb_midl_insert( IDL ids, ID id )
 int mdb_midl_append( IDL ids, ID id )
 {
        /* Too big? */
-       if (ids[0] >= MDB_IDL_UM_SIZE)
+       if (ids[0] >= MDB_IDL_UM_MAX)
                return -1;
        ids[0]++;
        ids[ids[0]] = id;
@@ -244,7 +244,7 @@ int mdb_mid2l_insert( ID2L ids, ID2 *id )
                return -1;
        }
 
-       if ( ids[0].mid >= MDB_IDL_DB_MAX ) {
+       if ( ids[0].mid >= MDB_IDL_UM_MAX ) {
                /* too big */
                return -2;
 
index 8e4a6e3c1baef06395c9ffeeb72390bd7cdd3dd9..7ef2cc53b2edd3ef194703bc6f9235023e6dc1d1 100644 (file)
@@ -101,12 +101,14 @@ typedef ID *IDL;
 #define MDB_IDL_N( ids )               ( MDB_IDL_IS_RANGE(ids) \
        ? ((ids)[2]-(ids)[1])+1 : (ids)[0] )
 
+#if 0  /* superseded by append/sort */
        /** Insert an ID into an IDL.
         * @param[in,out] ids   The IDL to insert into.
         * @param[in] id        The ID to insert.
         * @return      0 on success, -1 if the ID was already present in the IDL.
         */
 int mdb_midl_insert( IDL ids, ID id );
+#endif
 
        /** Append an ID onto an IDL.
         * @param[in,out] ids   The IDL to append to.