From: Pierangelo Masarati Date: Wed, 20 Apr 2005 18:52:10 +0000 (+0000) Subject: slightly reduce malloc overhead; minor cleanup X-Git-Tag: OPENLDAP_AC_BP~864 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c3fd851a59e41710dd026b3fd34209f82d983042;p=openldap slightly reduce malloc overhead; minor cleanup --- diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index 11093f2e6b..70968848b6 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -309,7 +309,7 @@ meta_back_dobind( struct metaconn *lc, Operation *op, ldap_back_send_t sendok ) return 1; } - for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); ++i, ++lsc ) { + for ( i = 0, lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); ++i, ++lsc ) { int rc; struct berval cred = BER_BVC(""); int msgid; @@ -432,7 +432,7 @@ meta_back_is_valid( struct metaconn *lc, int candidate ) return 0; } - for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ) && i < candidate; + for ( i = 0, lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ) && i < candidate; ++i, ++lsc ); if ( !META_LAST( lsc ) ) { @@ -512,7 +512,7 @@ meta_back_op_result( } } else { - for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); ++i, ++lsc ) { + for ( i = 0, lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); ++i, ++lsc ) { char *msg = NULL; char *match = NULL; diff --git a/servers/slapd/back-meta/compare.c b/servers/slapd/back-meta/compare.c index c9fc9fb137..950562e1ad 100644 --- a/servers/slapd/back-meta/compare.c +++ b/servers/slapd/back-meta/compare.c @@ -69,7 +69,7 @@ meta_back_compare( Operation *op, SlapReply *rs ) dc.rs = rs; dc.ctx = "compareDN"; - for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); ++i, ++lsc ) { + for ( i = 0, lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); ++i, ++lsc ) { struct berval mdn = BER_BVNULL; struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname; struct berval mapped_value = op->orc_ava->aa_value; @@ -171,7 +171,7 @@ meta_back_compare( Operation *op, SlapReply *rs ) /* * FIXME: should we check for abandon? */ - for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); lsc++, i++ ) { + for ( i = 0, lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); lsc++, i++ ) { int lrc; LDAPMessage *res = NULL; diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index cfabeb1753..d71a36be3f 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -128,19 +128,14 @@ metaconn_alloc( int ntargets ) assert( ntargets > 0 ); - lc = ch_calloc( sizeof( struct metaconn ), 1 ); + /* malloc once only; leave an extra one for one-past-end */ + lc = ch_malloc( sizeof( struct metaconn ) + + sizeof( struct metasingleconn ) * ( ntargets + 1 ) ); if ( lc == NULL ) { return NULL; } - - /* - * make it a null-terminated array ... - */ - lc->mc_conns = ch_calloc( sizeof( struct metasingleconn ), ntargets + 1 ); - if ( lc->mc_conns == NULL ) { - free( lc ); - return NULL; - } + + lc->mc_conns = (struct metasingleconn *)&lc[ 1 ]; /* FIXME: needed by META_LAST() */ lc->mc_conns[ ntargets ].msc_candidate = META_LAST_CONN; @@ -171,10 +166,6 @@ metaconn_free( return; } - if ( lc->mc_conns ) { - ch_free( lc->mc_conns ); - } - free( lc ); } diff --git a/servers/slapd/back-meta/init.c b/servers/slapd/back-meta/init.c index cb3cc111f6..022be04543 100644 --- a/servers/slapd/back-meta/init.c +++ b/servers/slapd/back-meta/init.c @@ -104,7 +104,9 @@ conn_free( struct metaconn *lc = v_lc; struct metasingleconn *lsc; - for ( lsc = lc->mc_conns; !META_LAST( lsc ); lsc++ ) { + assert( lc->mc_conns != NULL ); + + for ( lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); lsc++ ) { if ( lsc->msc_ld != NULL ) { ldap_unbind_ext_s( lsc->msc_ld, NULL, NULL ); } @@ -117,7 +119,7 @@ conn_free( ber_memfree( lsc->msc_cred.bv_val ); } } - free( lc->mc_conns ); + free( lc ); } diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index 43f5c2062c..e3bde3cdab 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -96,7 +96,7 @@ meta_back_search( Operation *op, SlapReply *rs ) /* * Inits searches */ - for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); ++i, ++lsc ) { + for ( i = 0, lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); ++i, ++lsc ) { struct berval realbase = op->o_req_dn; int realscope = op->ors_scope; ber_len_t suffixlen = 0; @@ -300,7 +300,7 @@ new_candidate:; /* check for abandon */ ab = op->o_abandon; - for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); lsc++, i++ ) { + for ( i = 0, lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); lsc++, i++ ) { if ( msgid[ i ] == -1 ) { continue; } diff --git a/servers/slapd/back-meta/unbind.c b/servers/slapd/back-meta/unbind.c index c60ee05f0b..8001da7dec 100644 --- a/servers/slapd/back-meta/unbind.c +++ b/servers/slapd/back-meta/unbind.c @@ -26,6 +26,7 @@ #include #include +#include #include "slap.h" #include "../back-ldap/back-ldap.h" @@ -70,8 +71,6 @@ meta_back_conn_destroy( rewrite_session_delete( li->mi_targets[ i ]->mt_rwmap.rwm_rw, conn ); meta_clear_one_candidate( &lc->mc_conns[ i ] ); } - - free( lc->mc_conns ); free( lc ); }