]> git.sur5r.net Git - openldap/commitdiff
Use attr_valfind instead of value_find_ex to optimize lookups
authorHoward Chu <hyc@openldap.org>
Mon, 24 Sep 2007 05:02:31 +0000 (05:02 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 24 Sep 2007 05:02:31 +0000 (05:02 +0000)
16 files changed:
servers/slapd/aci.c
servers/slapd/acl.c
servers/slapd/attr.c
servers/slapd/back-bdb/compare.c
servers/slapd/back-monitor/compare.c
servers/slapd/back-sql/compare.c
servers/slapd/backend.c
servers/slapd/bconfig.c
servers/slapd/compare.c
servers/slapd/filterentry.c
servers/slapd/overlays/dynlist.c
servers/slapd/overlays/syncprov.c
servers/slapd/schema_check.c
servers/slapd/slap.h
servers/slapd/slapi/slapi_utils.c
servers/slapd/syncrepl.c

index ac786ace756f4faad96051293d1125abf3ebd89d..0acf6c108ff38848a953c28454866a33390b613c 100644 (file)
@@ -592,11 +592,10 @@ aci_mask(
                                at != NULL;
                                at = attrs_find( at->a_next, ad ) )
                {
-                       if ( value_find_ex( ad,
+                       if ( attr_valfind( at, 
                                SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                        SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                               at->a_nvals,
-                               &op->o_ndn, op->o_tmpmemctx ) == 0 )
+                               &op->o_ndn, NULL, op->o_tmpmemctx ) == 0 )
                        {
                                rc = 1;
                                break;
index 8e9057ec680025b2848fa1923ada2da3d23513f8..adcfc1508484949509e67f11ec97fd8128021007 100644 (file)
@@ -974,11 +974,10 @@ acl_mask_dnattr(
                at != NULL;
                at = attrs_find( at->a_next, bdn->a_at ) )
        {
-               if ( value_find_ex( bdn->a_at,
+               if ( attr_valfind( at,
                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                       at->a_nvals,
-                       &bv, op->o_tmpmemctx ) == 0 )
+                       &bv, NULL, op->o_tmpmemctx ) == 0 )
                {
                        /* found it */
                        match = 1;
index 7112358c1e5b25f6aef363b8aaa9a2a768c0b449..e66b65a84120d0f296016f1f65e52b869651e2a3 100644 (file)
@@ -211,6 +211,7 @@ attrs_free( Attribute *a )
 static void
 attr_dup2( Attribute *tmp, Attribute *a )
 {
+       tmp->a_flags = a->a_flags & SLAP_ATTR_PERSISTENT_FLAGS;
        if ( a->a_vals != NULL ) {
                int     i;
 
@@ -290,11 +291,16 @@ attr_valfind(
        void *ctx )
 {
        struct berval nval = BER_BVNULL, *cval;
-       MatchingRule *mr = a->a_desc->ad_type->sat_equality;
+       MatchingRule *mr;
        const char *text;
        int match = -1, rc;
        unsigned i;
 
+       if ( flags & SLAP_MR_ORDERING )
+               mr = a->a_desc->ad_type->sat_ordering;
+       else
+               mr = a->a_desc->ad_type->sat_equality;
+
        if( !SLAP_IS_MR_ASSERTED_VALUE_NORMALIZED_MATCH( flags ) &&
                mr->smr_normalize )
        {
@@ -319,15 +325,19 @@ attr_valfind(
                while ( 0 < n ) {
                        unsigned pivot = n >> 1;
                        i = base + pivot;
+                       if ( i >= a->a_numvals ) {
+                               i = a->a_numvals - 1;
+                               break;
+                       }
                        rc = value_match( &match, a->a_desc, mr, flags,
                                &a->a_nvals[i], cval, &text );
                        if ( rc == LDAP_SUCCESS && match == 0 )
                                break;
                        n = pivot;
-                       if ( match > 0 )
+                       if ( match < 0 )
                                base = i+1;
                }
-               if ( match > 0 )
+               if ( match < 0 )
                        i++;
        } else {
        /* Linear search */
@@ -340,7 +350,8 @@ attr_valfind(
                                break;
                }
        }
-       *slot = i;
+       if ( slot )
+               *slot = i;
        if ( match )
                rc = LDAP_NO_SUCH_ATTRIBUTE;
        if ( nval.bv_val )
@@ -395,14 +406,14 @@ attr_valadd(
                                        rc = LDAP_TYPE_OR_VALUE_EXISTS;
                                return rc;
                        }
-                       for ( j = a->a_numvals; j > slot; j-- ) {
+                       for ( j = a->a_numvals; j >= slot; j-- ) {
                                a->a_vals[j+1] = a->a_vals[j];
                                if ( nvals )
                                        a->a_nvals[j+1] = a->a_nvals[j];
                        }
-                       ber_dupbv( &a->a_nvals[j], &v2[i] );
+                       ber_dupbv( &a->a_nvals[slot], &v2[i] );
                        if ( nvals )
-                               ber_dupbv( &a->a_vals[j], &vals[i] );
+                               ber_dupbv( &a->a_vals[slot], &vals[i] );
                        a->a_numvals++;
                }
                BER_BVZERO( &a->a_vals[a->a_numvals] );
index 972071314c1df14ad87c8f4f56f8e94f3727212a..538d1da61a32d3b7da8719c58db1fffa25840c0f 100644 (file)
@@ -158,10 +158,10 @@ dn2entry_retry:
        {
                rs->sr_err = LDAP_COMPARE_FALSE;
 
-               if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
+               if ( attr_valfind( a,
                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                       a->a_nvals, &op->oq_compare.rs_ava->aa_value,
+                       &op->oq_compare.rs_ava->aa_value, NULL,
                        op->o_tmpmemctx ) == 0 )
                {
                        rs->sr_err = LDAP_COMPARE_TRUE;
index 3a8df66624c29f16ea9093b82eaa169708566282..9cac645bc92daaf0fbd377d83d3b3f72e2b952b4 100644 (file)
@@ -71,10 +71,10 @@ monitor_back_compare( Operation *op, SlapReply *rs )
                        a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc )) {
                rs->sr_err = LDAP_COMPARE_FALSE;
 
-               if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
+               if ( attr_valfind( a,
                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                       a->a_nvals, &op->oq_compare.rs_ava->aa_value,
+                       &op->oq_compare.rs_ava->aa_value, NULL,
                        op->o_tmpmemctx ) == 0 )
                {
                        rs->sr_err = LDAP_COMPARE_TRUE;
index 24fe2e9fb126ffcef5ec54bff196ba34d957e0ef..403e82c3e578ba6d04dd31b3db4f64e4ce7f582e 100644 (file)
@@ -131,11 +131,10 @@ backsql_compare( Operation *op, SlapReply *rs )
                        a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ) )
        {
                rs->sr_err = LDAP_COMPARE_FALSE;
-               if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
+               if ( attr_valfind( a,
                                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                        SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                                       a->a_nvals,
-                                       &op->oq_compare.rs_ava->aa_value,
+                                       &op->oq_compare.rs_ava->aa_value, NULL,
                                        op->o_tmpmemctx ) == 0 )
                {
                        rs->sr_err = LDAP_COMPARE_TRUE;
index eb766d349d95ebec6bd6389a7818b9ec87915d22..3eb2a679d4bfeefa6dc3a3371d9dcef9968b8be1 100644 (file)
@@ -1501,10 +1501,10 @@ loopit:
                                op->o_bd = b2;
 
                        } else {
-                               rc = value_find_ex( group_at,
+                               rc = attr_valfind( a,
                                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                        SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                                       a->a_nvals, op_ndn, op->o_tmpmemctx );
+                                       op_ndn, NULL, op->o_tmpmemctx );
                                if ( rc == LDAP_NO_SUCH_ATTRIBUTE ) {
                                        rc = LDAP_COMPARE_FALSE;
                                }
index d83ac375203cc2328f6bfec63da8217e018d3821..7576a2c2f75e3bccbefd1f13cfafeb86c14ca823 100644 (file)
@@ -1525,6 +1525,7 @@ sortval_reject:
                                }
                                svtail = sv;
                        }
+                       sv->al_next = NULL;
                        for ( sv = svnew; sv; sv = sv->al_next )
                                sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
                        for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
index eaee0c0e9bd3ceecc9f2e2cda2e8f1bd84b6a0a4..1af6ba0b6aa8905fcdb88a428af12e158eeaf964 100644 (file)
@@ -384,10 +384,10 @@ static int compare_entry(
                        break;
                }
 
-               if ( value_find_ex( ava->aa_desc,
+               if ( attr_valfind( a, 
                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                       a->a_nvals, &ava->aa_value, op->o_tmpmemctx ) == 0 )
+                       &ava->aa_value, NULL, op->o_tmpmemctx ) == 0 )
                {
                        rc = LDAP_COMPARE_TRUE;
                        break;
index 7d5fabfbc3d7ab88c2bdcf8fcf9cea958816e3c8..ba53221d9d2e07b13d15b2aa85370caec4da58d0 100644 (file)
@@ -657,6 +657,29 @@ test_ava_filter(
                        continue;
                }
 
+               if ( a->a_flags & SLAP_ATTR_SORTED_VALS ) {
+                       unsigned slot;
+                       rc = attr_valfind( a, use | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH |
+                               SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, 
+                               &ava->aa_value, &slot, NULL );
+                       if ( rc == LDAP_SUCCESS )
+                               return LDAP_COMPARE_TRUE;
+                       if ( rc == LDAP_NO_SUCH_ATTRIBUTE ) {
+                               /* If insertion point is not the end of the list, there was
+                                * at least one value greater than the assertion.
+                                */
+                               if ( type == LDAP_FILTER_GE && slot < a->a_numvals )
+                                       return LDAP_COMPARE_TRUE;
+                               /* Likewise, if insertion point is not the head of the list,
+                                * there was at least one value less than the assertion.
+                                */
+                               if ( type == LDAP_FILTER_LE && slot > 0 )
+                                       return LDAP_COMPARE_TRUE;
+                               return LDAP_COMPARE_FALSE;
+                       }
+                       return rc;
+               }
+
 #ifdef LDAP_COMP_MATCH
                if ( nibble_mem_allocator && ava->aa_cf && !a->a_comp_data ) {
                        /* Component Matching */
index 1b58fe4bef6cf7e046c79a6d9e8fca4dafb4d07d..ef75f011673088c189c5bd04e3f8b4856626f3aa 100644 (file)
@@ -92,10 +92,10 @@ dynlist_is_dynlist_next( Operation *op, SlapReply *rs, dynlist_info_t *old_dli )
        }
 
        for ( ; dli; dli = dli->dli_next ) {
-               if ( value_find_ex( slap_schema.si_ad_objectClass, 
+               if ( attr_valfind( a,
                                SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                               a->a_nvals, &dli->dli_oc->soc_cname,
+                               &dli->dli_oc->soc_cname, NULL,
                                op->o_tmpmemctx ) == 0 )
                {
                        return dli;
@@ -723,10 +723,10 @@ done:;
                        /* if we're here, we got a match... */
                        rs->sr_err = LDAP_COMPARE_FALSE;
 
-                       if ( value_find_ex( op->orc_ava->aa_desc,
+                       if ( attr_valfind( a,
                                SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                        SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                               a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
+                               &op->orc_ava->aa_value, NULL, op->o_tmpmemctx ) == 0 )
                        {
                                rs->sr_err = LDAP_COMPARE_TRUE;
                                break;
index 3cdcbf0c789eb4daac51a59c9a62f4f8ad29a566..9cae2c53dc3212cf2ba6ddad9d467be00bf67b58 100644 (file)
@@ -1680,10 +1680,10 @@ syncprov_op_compare( Operation *op, SlapReply *rs )
 
                rs->sr_err = LDAP_COMPARE_FALSE;
 
-               if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
+               if ( attr_valfind( &a,
                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                               a.a_nvals, &op->oq_compare.rs_ava->aa_value, op->o_tmpmemctx ) == 0 )
+                               &op->oq_compare.rs_ava->aa_value, NULL, op->o_tmpmemctx ) == 0 )
                {
                        rs->sr_err = LDAP_COMPARE_TRUE;
                }
index a5860d7dc9fd9b0128fc562f2484962e665b4df8..4c0d376249473159d7083f03e99014b8b13b36ff 100644 (file)
@@ -856,9 +856,9 @@ entry_naming_check(
                        break;
                }
 
-               rc = value_find_ex( desc, SLAP_MR_VALUE_OF_ASSERTION_SYNTAX|
+               rc = attr_valfind( attr, SLAP_MR_VALUE_OF_ASSERTION_SYNTAX|
                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
-                       attr->a_nvals, &ava->la_value, NULL );
+                       &ava->la_value, NULL, NULL );
 
                if( rc != 0 ) {
                        switch( rc ) {
index bbcc3437b83f14481a71d54bab866dfd5f39903b..65319e1a6ef0955e7115a77c4950eef92c9469b9 100644 (file)
@@ -1131,6 +1131,11 @@ struct Attribute {
 #define SLAP_ATTR_DONT_FREE_DATA       0x4U
 #define SLAP_ATTR_DONT_FREE_VALS       0x8U
 #define        SLAP_ATTR_SORTED_VALS           0x10U   /* values are sorted */
+
+/* These flags persist across an attr_dup() */
+#define        SLAP_ATTR_PERSISTENT_FLAGS \
+       SLAP_ATTR_SORTED_VALS
+
        Attribute               *a_next;
 #ifdef LDAP_COMP_MATCH
        ComponentData           *a_comp_data;   /* component values */
index 446fd80f4c453a8b7dc5e322cbd667bf44b262b1..6c37e3b7f45be8d67baee5523e818ee0e97367a8 100644 (file)
@@ -2152,28 +2152,15 @@ int slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const st
 
 int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v )
 {
-       MatchingRule *mr;
-       struct berval *bv;
-       int j;
-       const char *text;
        int rc;
        int ret;
 
        if ( a ->a_vals == NULL ) {
                return -1;
        }
-       mr = a->a_desc->ad_type->sat_equality;
-       for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
-               rc = value_match( &ret, a->a_desc, mr,
-                       SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, bv, v, &text );
-               if ( rc != LDAP_SUCCESS ) {
-                       return -1;
-               }
-               if ( ret == 0 ) {
-                       return 0;
-               }
-       }
-       return -1;
+       rc = attr_valfind( (Attribute *)a, SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, v,
+               NULL, NULL );
+       return rc == 0 ? 0 : -1;
 }
 
 int slapi_attr_type_cmp( const char *t1, const char *t2, int opt )
index ea94e4e2794c4f6148e6204c7b7f6fccd2f39cf9..a657088bed3fec522844fc5fc38ecde27c922a88 100644 (file)
@@ -2858,11 +2858,11 @@ dn_callback(
                                        oldRDN.bv_len -= oldVal.bv_len + 2;
                                        slap_bv2ad( &oldRDN, &ad, &rs->sr_text );
                                        a = attr_find( dni->new_entry->e_attrs, ad );
-                                       if ( !a || value_find_ex( ad,
+                                       if ( !a || attr_valfind( a,
                                                SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH |
                                                SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
-                                               SLAP_MR_VALUE_OF_SYNTAX, a->a_nvals,
-                                               &oldVal, op->o_tmpmemctx ) != LDAP_SUCCESS )
+                                               SLAP_MR_VALUE_OF_SYNTAX,
+                                               &oldVal, NULL, op->o_tmpmemctx ) != LDAP_SUCCESS )
                                        {
                                                dni->delOldRDN = 1;
                                        }