From a3547e27589cd83d24faa06bf669425ca610abd0 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 23 Sep 2007 04:40:16 +0000 Subject: [PATCH] More for a_numvals --- servers/slapd/back-ldap/search.c | 9 ++------- servers/slapd/back-sql/entry-id.c | 4 ++-- servers/slapd/backend.c | 4 +--- servers/slapd/filterentry.c | 7 +------ servers/slapd/overlays/accesslog.c | 14 +++----------- servers/slapd/overlays/dynlist.c | 3 +-- servers/slapd/overlays/pcache.c | 3 +-- servers/slapd/overlays/rwm.c | 11 ++++------- servers/slapd/overlays/syncprov.c | 6 ++---- servers/slapd/overlays/valsort.c | 4 +--- servers/slapd/syncrepl.c | 4 +--- 11 files changed, 19 insertions(+), 50 deletions(-) diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 69d03ce0a2..3d23276bf1 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -676,13 +676,7 @@ ldap_build_entry( * values result filter */ attr->a_vals = (struct berval *)&slap_dummy_bv; - last = 0; - - } else { - for ( last = 0; !BER_BVISNULL( &attr->a_vals[ last ] ); last++ ) - /* just count vals */ ; } - attr->a_numvals = last; validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate; pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty; @@ -693,7 +687,7 @@ ldap_build_entry( goto next_attr; } - for ( i = 0; i < last; i++ ) { + for ( i = 0; !BER_BVISNULL( &attr->a_vals[i] ); i++ ) { struct berval pval; int rc; @@ -725,6 +719,7 @@ ldap_build_entry( attr->a_vals[i] = pval; } } + attr->a_numvals = last = i; if ( last && attr->a_desc->ad_type->sat_equality && attr->a_desc->ad_type->sat_equality->smr_normalize ) diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index 2f8b93820d..f61fc5c864 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -617,8 +617,7 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) BerVarray tmp; if ( attr->a_vals != NULL ) { - for ( ; !BER_BVISNULL( &attr->a_vals[ oldcount ] ); oldcount++ ) - /* just count */ ; + oldcount = attr->a_numvals; } tmp = ch_realloc( attr->a_vals, ( oldcount + count + 1 ) * sizeof( struct berval ) ); @@ -639,6 +638,7 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) } else { attr->a_nvals = attr->a_vals; } + attr->a_numvals += count; } else { append = 1; diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 3d83060f55..eb766d349d 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -1648,9 +1648,7 @@ fe_acl_attribute( goto freeit; } - for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) - ; - + i = a->a_numvals; v = op->o_tmpalloc( sizeof(struct berval) * ( i + 1 ), op->o_tmpmemctx ); for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) diff --git a/servers/slapd/filterentry.c b/servers/slapd/filterentry.c index d1fb4856e3..7d5fabfbc3 100644 --- a/servers/slapd/filterentry.c +++ b/servers/slapd/filterentry.c @@ -212,12 +212,7 @@ static int test_mra_filter( if ( mra->ma_cf && mra->ma_rule->smr_usage & SLAP_MR_COMPONENT ) { num_attr_vals = 0; if ( !a->a_comp_data ) { - for ( ; - !BER_BVISNULL( &a->a_vals[num_attr_vals] ); - num_attr_vals++ ) - { - /* empty */; - } + num_attr_vals = a->a_numvals; if ( num_attr_vals <= 0 ) { /* no attribute value */ return LDAP_INAPPROPRIATE_MATCHING; diff --git a/servers/slapd/overlays/accesslog.c b/servers/slapd/overlays/accesslog.c index 646c9a8d1f..e0b0e8bb02 100644 --- a/servers/slapd/overlays/accesslog.c +++ b/servers/slapd/overlays/accesslog.c @@ -1365,11 +1365,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) { /* count all the vals */ i = 0; for ( a=e2->e_attrs; a; a=a->a_next ) { - if ( a->a_vals ) { - for (b=a->a_vals; !BER_BVISNULL( b ); b++) { - i++; - } - } + i += a->a_numvals; } vals = ch_malloc( (i+1) * sizeof( struct berval )); i = 0; @@ -1396,9 +1392,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) { i = 0; for ( m = op->orm_modlist; m; m = m->sml_next ) { if ( m->sml_values ) { - for ( b = m->sml_values; !BER_BVISNULL( b ); b++ ) { - i++; - } + i += m->sml_numvals; } else if ( m->sml_op == LDAP_MOD_DELETE || m->sml_op == LDAP_MOD_REPLACE ) { @@ -1494,9 +1488,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) { i = 0; for ( a = old->e_attrs; a != NULL; a = a->a_next ) { if ( a->a_vals && a->a_flags ) { - for ( b = a->a_vals; !BER_BVISNULL( b ); b++ ) { - i++; - } + i += a->a_numvals; } } vals = ch_malloc( (i + 1) * sizeof( struct berval ) ); diff --git a/servers/slapd/overlays/dynlist.c b/servers/slapd/overlays/dynlist.c index 965b6b5535..7e8a50ca3b 100644 --- a/servers/slapd/overlays/dynlist.c +++ b/servers/slapd/overlays/dynlist.c @@ -248,8 +248,7 @@ dynlist_sc_update( Operation *op, SlapReply *rs ) } /* test access to attribute */ - for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) - /* just count */ ; + i = a->a_numvals; vals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx ); if ( a->a_nvals != a->a_vals ) { diff --git a/servers/slapd/overlays/pcache.c b/servers/slapd/overlays/pcache.c index 71e04db825..5506c22e3a 100644 --- a/servers/slapd/overlays/pcache.c +++ b/servers/slapd/overlays/pcache.c @@ -1367,8 +1367,7 @@ remove_func ( attr = attr_find( rs->sr_entry->e_attrs, ad_queryId ); if ( attr == NULL ) return 0; - for ( count = 0; !BER_BVISNULL( &attr->a_vals[count] ); count++ ) - ; + count = attr->a_numvals; assert( count > 0 ); qi = op->o_tmpalloc( sizeof( struct query_info ), op->o_tmpmemctx ); qi->next = op->o_callback->sc_private; diff --git a/servers/slapd/overlays/rwm.c b/servers/slapd/overlays/rwm.c index 47068cda38..1afb4654f3 100644 --- a/servers/slapd/overlays/rwm.c +++ b/servers/slapd/overlays/rwm.c @@ -226,9 +226,7 @@ rwm_op_add( Operation *op, SlapReply *rs ) { int j, last; - for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[ last ] ); last++ ) - /* count values */ ; - last--; + last = (*ap)->a_numvals - 1; for ( j = 0; !BER_BVISNULL( &(*ap)->a_vals[ j ] ); j++ ) { struct ldapmapping *mapping = NULL; @@ -245,6 +243,7 @@ rwm_op_add( Operation *op, SlapReply *rs ) (*ap)->a_vals[ j ] = (*ap)->a_vals[ last ]; } BER_BVZERO( &(*ap)->a_vals[ last ] ); + (*ap)->a_numvals--; last--; j--; } @@ -1054,9 +1053,8 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN ) mapping->m_dst_ad->ad_type->sat_equality->smr_normalize ) { int i = 0; - for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ ) - /* just count */ ; + last = (*ap)->a_numvals; if ( last ) { (*ap)->a_nvals = ch_malloc( (last+1) * sizeof(struct berval) ); @@ -1105,8 +1103,7 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN ) } if ( last == -1 ) { /* not yet counted */ - for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ ) - /* just count */ ; + last = (*ap)->a_numvals; } if ( last == 0 ) { diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index 8a3c6817b1..72d2b330cc 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -2554,11 +2554,9 @@ syncprov_db_open( a = attr_find( e->e_attrs, slap_schema.si_ad_contextCSN ); if ( a ) { - int i; ber_bvarray_dup_x( &si->si_ctxcsn, a->a_vals, NULL ); - for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ); - si->si_numcsns = i; - si->si_sids = slap_parse_csn_sids( si->si_ctxcsn, i, NULL ); + si->si_numcsns = a->a_numvals; + si->si_sids = slap_parse_csn_sids( si->si_ctxcsn, a->a_numvals, NULL ); } overlay_entry_release_ov( op, e, 0, on ); if ( si->si_ctxcsn ) { diff --git a/servers/slapd/overlays/valsort.c b/servers/slapd/overlays/valsort.c index 5950a208c4..5cc06cfaf0 100644 --- a/servers/slapd/overlays/valsort.c +++ b/servers/slapd/overlays/valsort.c @@ -304,9 +304,7 @@ valsort_response( Operation *op, SlapReply *rs ) a = attr_find( rs->sr_entry->e_attrs, vi->vi_ad ); } - /* count values */ - for ( n = 0; !BER_BVISNULL( &a->a_vals[n] ); n++ ); - + n = a->a_numvals; if ( vi->vi_sort & VALSORT_WEIGHTED ) { int j, gotnvals; long *index = op->o_tmpalloc( n * sizeof(long), op->o_tmpmemctx ); diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index 86a81f32d3..2ab959c858 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -562,9 +562,7 @@ do_syncrep1( ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_mutex ); rc = backend_operational( op, &rs ); if ( rc == LDAP_SUCCESS && a.a_vals ) { - int num; - for (i=0; !BER_BVISNULL( &a.a_vals[i] ); i++) ; - num = i; + int num = a.a_numvals; /* check for differences */ if ( num != si->si_cookieState->cs_num ) { changed = 1; -- 2.39.5