slightly reduce malloc overhead; minor cleanup

This commit is contained in:
Pierangelo Masarati 2005-04-20 18:52:10 +00:00
parent c66a92f935
commit c3fd851a59
6 changed files with 17 additions and 25 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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 );
}

View file

@ -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 );
}

View file

@ -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;
}

View file

@ -26,6 +26,7 @@
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/errno.h>
#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 );
}