From: Kurt Zeilenga Date: Wed, 11 Aug 1999 02:57:07 +0000 (+0000) Subject: Removed redundant dn_normalization(strdup(ndn)) from dn2id codes. X-Git-Tag: TWEB_OL_BASE~236 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=82ac9547c9dc518d468f8b27bea169d02f8df17e;p=openldap Removed redundant dn_normalization(strdup(ndn)) from dn2id codes. Added initial DN_INDICES code behind #ifdef DN_INDICES. Generates only equality index. Will add parent and subtree indices next. --- diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index a65c622645..bd2613d561 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -24,6 +24,11 @@ LDAP_BEGIN_DECL #define SUBLEN 3 +/* #define DN_INDICES 1 *//* generate dn eq, subtree, and parent indices */ +#define DN_EQ_PREFIX '=' +#define DN_SUBTREE_PREFIX '+' +#define DN_PARENT_PREFIX '-' + /* * there is a single index for each attribute. these prefixes ensure * that there is no collision among keys. @@ -35,7 +40,8 @@ LDAP_BEGIN_DECL /* allow 3 characters per byte + PREFIX + EOS */ #define CONT_SIZE ( sizeof(long)*3 + 1 + 1 ) -/* #define CONT_POSTFIX 1 *//* postfix original key */ + +#undef CONT_POSTFIX /* postfix original key */ #define UNKNOWN_PREFIX '?' /* prefix for unknown keys */ diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index 04d219d188..7bfb1078e2 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -39,11 +39,15 @@ dn2id_add( return( -1 ); } - dn = ch_strdup( dn ); - (void) dn_normalize_case( dn ); - +#ifndef DN_INDICES key.dptr = dn; - key.dsize = strlen( dn ) + 1; + key.dsize = strlen( key.dptr ) + 1; +#else + key.dsize = strlen( dn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_EQ_PREFIX, dn ); +#endif + data.dptr = (char *) &id; data.dsize = sizeof(ID); @@ -52,9 +56,12 @@ dn2id_add( rc = ldbm_cache_store( db, key, data, flags ); - free( dn ); ldbm_cache_close( be, db ); +#ifdef DN_INDICES + free( key.dptr ); +#endif + Debug( LDAP_DEBUG_TRACE, "<= dn2id_add %d\n", rc, 0, 0 ); return( rc ); } @@ -73,13 +80,10 @@ dn2id( ldbm_datum_init( key ); ldbm_datum_init( data ); - dn = ch_strdup( dn ); Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn, 0, 0 ); - (void) dn_normalize_case( dn ); /* first check the cache */ if ( (id = cache_find_entry_dn2id( be, &li->li_cache, dn )) != NOID ) { - free( dn ); Debug( LDAP_DEBUG_TRACE, "<= dn2id %ld (in cache)\n", id, 0, 0 ); return( id ); @@ -87,19 +91,27 @@ dn2id( if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) == NULL ) { - free( dn ); Debug( LDAP_DEBUG_ANY, "<= dn2id could not open dn2id%s\n", LDBM_SUFFIX, 0, 0 ); return( NOID ); } +#ifndef DN_INDICES key.dptr = dn; - key.dsize = strlen( dn ) + 1; + key.dsize = strlen( key.dptr ) + 1; +#else + key.dsize = strlen( dn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_EQ_PREFIX, dn ); +#endif data = ldbm_cache_fetch( db, key ); ldbm_cache_close( be, db ); - free( dn ); + +#ifdef DN_INDICES + free( key.dptr ); +#endif if ( data.dptr == NULL ) { Debug( LDAP_DEBUG_TRACE, "<= dn2id NOID\n", 0, 0, 0 ); @@ -136,14 +148,20 @@ dn2id_delete( return( -1 ); } - dn = ch_strdup( dn ); - (void) dn_normalize_case( dn ); +#ifndef DN_INDICES key.dptr = dn; - key.dsize = strlen( dn ) + 1; + key.dsize = strlen( key.dptr ) + 1; +#else + key.dsize = strlen( dn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_EQ_PREFIX, dn ); +#endif rc = ldbm_cache_delete( db, key ); - free( dn ); +#ifdef DN_INDICES + free( key.dptr ); +#endif ldbm_cache_close( be, db ); diff --git a/servers/slapd/tools/ldif2id2children.c b/servers/slapd/tools/ldif2id2children.c index 3acbbcf74e..4258a87aea 100644 --- a/servers/slapd/tools/ldif2id2children.c +++ b/servers/slapd/tools/ldif2id2children.c @@ -86,8 +86,14 @@ main( int argc, char **argv ) id ); } else { (void) dn_normalize_case( val ); +#ifndef DN_INDICES key.dptr = val; key.dsize = strlen( val ) + 1; +#else + key.dsize = strlen( val ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_EQ_PREFIX, val ); +#endif data.dptr = (char *) &id; data.dsize = sizeof(ID); if ( ldbm_store( db->dbc_db, key, data, @@ -95,6 +101,9 @@ main( int argc, char **argv ) perror( "dn2id ldbm_store" ); exit( EXIT_FAILURE ); } +#ifdef DN_INDICES + free( val ); +#endif } } if ( buf )