From: Howard Chu Date: Wed, 23 Apr 2003 10:26:06 +0000 (+0000) Subject: Change RDN compare funcs, we don't need lexical ordering X-Git-Tag: OPENLDAP_REL_ENG_2_2_0ALPHA~266 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=184f647b2560b9a939a1a696e95fc527b36930e1;p=openldap Change RDN compare funcs, we don't need lexical ordering --- diff --git a/servers/slapd/back-bdb/cache.c b/servers/slapd/back-bdb/cache.c index b4d0c9f231..ec1490061f 100644 --- a/servers/slapd/back-bdb/cache.c +++ b/servers/slapd/back-bdb/cache.c @@ -169,13 +169,14 @@ bdb_cache_entryinfo_destroy( EntryInfo *e ) } \ } while(0) -/* Do a lexical sort on normalized RDNs */ +/* Do a length-ordered sort on normalized RDNs */ static int bdb_rdn_cmp( const void *v_e1, const void *v_e2 ) { const EntryInfo *e1 = v_e1, *e2 = v_e2; - int rc = strncmp( e1->bei_nrdn.bv_val, e2->bei_nrdn.bv_val, e1->bei_nrdn.bv_len ); - if (rc == 0) rc = e1->bei_nrdn.bv_len - e2->bei_nrdn.bv_len; + int rc = e1->bei_nrdn.bv_len - e2->bei_nrdn.bv_len; + if (rc == 0) rc = strncmp( e1->bei_nrdn.bv_val, e2->bei_nrdn.bv_val, + e1->bei_nrdn.bv_len ); return rc; } @@ -288,8 +289,10 @@ bdb_entryinfo_add_internal( addkid = 0; cache->c_cursize -= incr; #ifdef BDB_HIER - if ( ei->bei_rdn.bv_val ) + if ( ei->bei_rdn.bv_val ) { ber_memfree_x( ei->bei_rdn.bv_val, NULL ); + ei->bei_rdn.bv_val = NULL; + } #endif } else { LRU_ADD( cache, ei2 ); diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index eed36ae231..51a5edc8fe 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -503,7 +503,7 @@ typedef struct diskNode { } diskNode; /* Sort function for the sorted duplicate data items of a dn2id key. - * Sorts based on normalized RDN, in lexical order. + * Sorts based on normalized RDN, in length order. */ int bdb_dup_compare( @@ -530,15 +530,9 @@ bdb_dup_compare( curlen = ptr[0] << 8 | *pt2; - if ( usrlen < 0 ) { - if ( curlen < 0 ) return 0; - return -1; - } - - if ( curlen < 0 ) return 1; + rc = usrlen - curlen; - rc = strncmp( usr->nrdn, cur->nrdn, usrlen ); - if ( rc == 0 ) rc = usrlen - curlen; + if ( rc == 0 ) rc = strncmp( usr->nrdn, cur->nrdn, usrlen ); return rc; }