Skip to content
Snippets Groups Projects
Commit 36f3c929 authored by Hallvard Furuseth's avatar Hallvard Furuseth Committed by Quanah Gibson-Mount
Browse files

back-bdb/back-mdb IDL cleanup.

Parenthesize macros.  Microoptimize IDL search.  Use RANGE_<FIRST/LAST>
when IDL is known to be a range.
parent 292860f0
No related branches found
No related tags found
No related merge requests found
...@@ -22,10 +22,9 @@ ...@@ -22,10 +22,9 @@
#include "back-bdb.h" #include "back-bdb.h"
#include "idl.h" #include "idl.h"
#define IDL_MAX(x,y) ( x > y ? x : y ) #define IDL_MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define IDL_MIN(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_CMP(x,y) ( x < y ? -1 : ( x > y ? 1 : 0 ) )
#define IDL_LRU_DELETE( bdb, e ) do { \ #define IDL_LRU_DELETE( bdb, e ) do { \
if ( (e) == (bdb)->bi_idl_lru_head ) { \ if ( (e) == (bdb)->bi_idl_lru_head ) { \
...@@ -109,7 +108,7 @@ unsigned bdb_idl_search( ID *ids, ID id ) ...@@ -109,7 +108,7 @@ unsigned bdb_idl_search( ID *ids, ID id )
* if not found, returns first postion greater than id * if not found, returns first postion greater than id
*/ */
unsigned base = 0; unsigned base = 0;
unsigned cursor = 0; unsigned cursor = 1;
int val = 0; int val = 0;
unsigned n = ids[0]; unsigned n = ids[0];
...@@ -118,27 +117,26 @@ unsigned bdb_idl_search( ID *ids, ID id ) ...@@ -118,27 +117,26 @@ unsigned bdb_idl_search( ID *ids, ID id )
#endif #endif
while( 0 < n ) { while( 0 < n ) {
int pivot = n >> 1; unsigned pivot = n >> 1;
cursor = base + pivot; cursor = base + pivot + 1;
val = IDL_CMP( id, ids[cursor + 1] ); val = IDL_CMP( id, ids[cursor] );
if( val < 0 ) { if( val < 0 ) {
n = pivot; n = pivot;
} else if ( val > 0 ) { } else if ( val > 0 ) {
base = cursor + 1; base = cursor;
n -= pivot + 1; n -= pivot + 1;
} else { } else {
return cursor + 1; return cursor;
} }
} }
if( val > 0 ) { if( val > 0 ) {
return cursor + 2; ++cursor;
} else {
return cursor + 1;
} }
return cursor;
#else #else
/* (reverse) linear search */ /* (reverse) linear search */
...@@ -171,11 +169,11 @@ int bdb_idl_insert( ID *ids, ID id ) ...@@ -171,11 +169,11 @@ int bdb_idl_insert( ID *ids, ID id )
if (BDB_IDL_IS_RANGE( ids )) { if (BDB_IDL_IS_RANGE( ids )) {
/* if already in range, treat as a dup */ /* 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; return -1;
if (id < BDB_IDL_FIRST(ids)) if (id < BDB_IDL_RANGE_FIRST(ids))
ids[1] = id; ids[1] = id;
else if (id > BDB_IDL_LAST(ids)) else if (id > BDB_IDL_RANGE_LAST(ids))
ids[2] = id; ids[2] = id;
return 0; return 0;
} }
...@@ -1091,8 +1089,8 @@ bdb_idl_intersection( ...@@ -1091,8 +1089,8 @@ bdb_idl_intersection(
* turn it into a range. * turn it into a range.
*/ */
if ( BDB_IDL_IS_RANGE( b ) if ( BDB_IDL_IS_RANGE( b )
&& BDB_IDL_FIRST( b ) <= BDB_IDL_FIRST( a ) && BDB_IDL_RANGE_FIRST( b ) <= BDB_IDL_RANGE_FIRST( a )
&& BDB_IDL_LAST( b ) >= BDB_IDL_LAST( a ) ) { && BDB_IDL_RANGE_LAST( b ) >= BDB_IDL_RANGE_LAST( a ) ) {
if (idmax - idmin + 1 == a[0]) if (idmax - idmin + 1 == a[0])
{ {
a[0] = NOID; a[0] = NOID;
...@@ -1311,11 +1309,11 @@ int bdb_idl_append_one( ID *ids, ID id ) ...@@ -1311,11 +1309,11 @@ int bdb_idl_append_one( ID *ids, ID id )
{ {
if (BDB_IDL_IS_RANGE( ids )) { if (BDB_IDL_IS_RANGE( ids )) {
/* if already in range, treat as a dup */ /* 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; return -1;
if (id < BDB_IDL_FIRST(ids)) if (id < BDB_IDL_RANGE_FIRST(ids))
ids[1] = id; ids[1] = id;
else if (id > BDB_IDL_LAST(ids)) else if (id > BDB_IDL_RANGE_LAST(ids))
ids[2] = id; ids[2] = id;
return 0; return 0;
} }
......
...@@ -61,12 +61,12 @@ ...@@ -61,12 +61,12 @@
#define BDB_IDL_ID( bdb, ids, id ) BDB_IDL_RANGE( ids, id, ((bdb)->bi_lastid) ) #define BDB_IDL_ID( bdb, ids, id ) BDB_IDL_RANGE( ids, id, ((bdb)->bi_lastid) )
#define BDB_IDL_ALL( bdb, ids ) BDB_IDL_RANGE( ids, 1, ((bdb)->bi_lastid) ) #define BDB_IDL_ALL( bdb, ids ) BDB_IDL_RANGE( ids, 1, ((bdb)->bi_lastid) )
#define BDB_IDL_FIRST( ids ) ( ids[1] ) #define BDB_IDL_FIRST( ids ) ( (ids)[1] )
#define BDB_IDL_LAST( ids ) ( BDB_IDL_IS_RANGE(ids) \ #define BDB_IDL_LAST( ids ) ( BDB_IDL_IS_RANGE(ids) \
? ids[2] : ids[ids[0]] ) ? (ids)[2] : (ids)[(ids)[0]] )
#define BDB_IDL_N( ids ) ( BDB_IDL_IS_RANGE(ids) \ #define BDB_IDL_N( ids ) ( BDB_IDL_IS_RANGE(ids) \
? (ids[2]-ids[1])+1 : ids[0] ) ? ((ids)[2]-(ids)[1])+1 : (ids)[0] )
LDAP_BEGIN_DECL LDAP_BEGIN_DECL
LDAP_END_DECL LDAP_END_DECL
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment