X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-bdb%2Fidl.c;h=3a4e95efbfb2804256f62517b1d1c1d5ac487139;hb=34adb8692935262a09e21c62d9bcd0284a272b0c;hp=481d9298e754f998402f9bf3c377d4ffe38725de;hpb=4af9eb971559e3a1f0432615e93ec870dc753ddb;p=openldap diff --git a/servers/slapd/back-bdb/idl.c b/servers/slapd/back-bdb/idl.c index 481d9298e7..3a4e95efbf 100644 --- a/servers/slapd/back-bdb/idl.c +++ b/servers/slapd/back-bdb/idl.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2000-2009 The OpenLDAP Foundation. + * Copyright 2000-2011 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,10 +22,9 @@ #include "back-bdb.h" #include "idl.h" -#define IDL_MAX(x,y) ( x > y ? x : y ) -#define IDL_MIN(x,y) ( x < y ? x : y ) - -#define IDL_CMP(x,y) ( x < y ? -1 : ( x > y ? 1 : 0 ) ) +#define IDL_MAX(x,y) ( (x) > (y) ? (x) : (y) ) +#define IDL_MIN(x,y) ( (x) < (y) ? (x) : (y) ) +#define IDL_CMP(x,y) ( (x) < (y) ? -1 : (x) > (y) ) #define IDL_LRU_DELETE( bdb, e ) do { \ if ( (e) == (bdb)->bi_idl_lru_head ) { \ @@ -109,7 +108,7 @@ unsigned bdb_idl_search( ID *ids, ID id ) * if not found, returns first postion greater than id */ unsigned base = 0; - unsigned cursor = 0; + unsigned cursor = 1; int val = 0; unsigned n = ids[0]; @@ -118,27 +117,26 @@ unsigned bdb_idl_search( ID *ids, ID id ) #endif while( 0 < n ) { - int pivot = n >> 1; - cursor = base + pivot; - val = IDL_CMP( id, ids[cursor + 1] ); + unsigned pivot = n >> 1; + cursor = base + pivot + 1; + val = IDL_CMP( id, ids[cursor] ); if( val < 0 ) { n = pivot; } else if ( val > 0 ) { - base = cursor + 1; + base = cursor; n -= pivot + 1; } else { - return cursor + 1; + return cursor; } } if( val > 0 ) { - return cursor + 2; - } else { - return cursor + 1; + ++cursor; } + return cursor; #else /* (reverse) linear search */ @@ -171,11 +169,11 @@ int bdb_idl_insert( ID *ids, ID id ) if (BDB_IDL_IS_RANGE( ids )) { /* if already in range, treat as a dup */ - if (id >= BDB_IDL_FIRST(ids) && id <= BDB_IDL_LAST(ids)) + if (id >= BDB_IDL_RANGE_FIRST(ids) && id <= BDB_IDL_RANGE_LAST(ids)) return -1; - if (id < BDB_IDL_FIRST(ids)) + if (id < BDB_IDL_RANGE_FIRST(ids)) ids[1] = id; - else if (id > BDB_IDL_LAST(ids)) + else if (id > BDB_IDL_RANGE_LAST(ids)) ids[2] = id; return 0; } @@ -219,7 +217,7 @@ int bdb_idl_insert( ID *ids, ID id ) return 0; } -static int bdb_idl_delete( ID *ids, ID id ) +int bdb_idl_delete( ID *ids, ID id ) { unsigned x; @@ -376,10 +374,10 @@ bdb_idl_cache_put( } bdb->bi_idl_lru_head = ee; - if ( ++bdb->bi_idl_cache_size > bdb->bi_idl_cache_max_size ) { + if ( bdb->bi_idl_cache_size >= bdb->bi_idl_cache_max_size ) { int i; - ee = bdb->bi_idl_lru_tail; - for ( i = 0; ee != NULL && i < 10; i++, ee = eprev ) { + eprev = bdb->bi_idl_lru_tail; + for ( i = 0; (ee = eprev) != NULL && i < 10; i++ ) { eprev = ee->idl_lru_prev; if ( eprev == ee ) { eprev = NULL; @@ -405,6 +403,7 @@ bdb_idl_cache_put( assert( bdb->bi_idl_lru_tail != NULL || bdb->bi_idl_lru_head == NULL ); } + bdb->bi_idl_cache_size++; ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock ); ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock ); } @@ -1090,8 +1089,8 @@ bdb_idl_intersection( * turn it into a range. */ if ( BDB_IDL_IS_RANGE( b ) - && BDB_IDL_FIRST( b ) <= BDB_IDL_FIRST( a ) - && BDB_IDL_LAST( b ) >= BDB_IDL_LAST( a ) ) { + && BDB_IDL_RANGE_FIRST( b ) <= BDB_IDL_RANGE_FIRST( a ) + && BDB_IDL_RANGE_LAST( b ) >= BDB_IDL_RANGE_LAST( a ) ) { if (idmax - idmin + 1 == a[0]) { a[0] = NOID; @@ -1310,11 +1309,11 @@ int bdb_idl_append_one( ID *ids, ID id ) { if (BDB_IDL_IS_RANGE( ids )) { /* if already in range, treat as a dup */ - if (id >= BDB_IDL_FIRST(ids) && id <= BDB_IDL_LAST(ids)) + if (id >= BDB_IDL_RANGE_FIRST(ids) && id <= BDB_IDL_RANGE_LAST(ids)) return -1; - if (id < BDB_IDL_FIRST(ids)) + if (id < BDB_IDL_RANGE_FIRST(ids)) ids[1] = id; - else if (id > BDB_IDL_LAST(ids)) + else if (id > BDB_IDL_RANGE_LAST(ids)) ids[2] = id; return 0; }