Skip to content
Permalink
Browse files

dialog: Optimize link_dlg_profile()

Reduce the number of pointer de-reference operations performed, be it
under lock or not (from 8-9 de-references down to just 1).
  • Loading branch information
liviuchircu committed Sep 27, 2019
1 parent e2c0791 commit 082329764936a4c244ae22cc0b49af9ce3941a5c
Showing with 19 additions and 20 deletions.
  1. +19 −20 modules/dialog/dlg_profile.c
@@ -778,13 +778,13 @@ static int link_dlg_profile(struct dlg_profile_link *linker,
struct dlg_entry *d_entry;
void ** dest;
struct prof_local_count *cnt;
struct dlg_profile_table *profile = linker->profile;
str shtag = {0,0};

/* insert into profile hash table */
/* but only if cachedb is not used */
if (!(linker->profile->repl_type==REPL_CACHEDB)) {
if (profile->repl_type != REPL_CACHEDB) {
/* calculate the hash position */
hash = calc_hash_profile(&linker->value, dlg, linker->profile);
hash = calc_hash_profile(&linker->value, dlg, profile);
linker->hash_idx = hash;

if (linker->profile->repl_type==REPL_PROTOBIN &&
@@ -793,39 +793,38 @@ static int link_dlg_profile(struct dlg_profile_link *linker,
return -1;
}

lock_set_get( linker->profile->locks, hash );
lock_set_get(profile->locks, hash);

LM_DBG("Entered here with hash = %d \n",hash);
if( linker->profile->has_value)
{
p_entry = linker->profile->entries[hash];
dest = map_get( p_entry, linker->value );
if (profile->has_value) {
p_entry = profile->entries[hash];
dest = map_get(p_entry, linker->value);
if (!dest) {
LM_ERR("No more shm memory\n");
lock_set_release( linker->profile->locks,hash );
lock_set_release( profile->locks,hash );
return -1;
}

prof_val_local_inc(dest, &shtag,
linker->profile->repl_type==REPL_PROTOBIN);
profile->repl_type == REPL_PROTOBIN);
}
else {
if (linker->profile->repl_type==REPL_PROTOBIN && profile_repl_cluster) {
cnt = get_local_counter(&linker->profile->noval_local_counters[hash],
if (profile->repl_type == REPL_PROTOBIN && profile_repl_cluster) {
cnt = get_local_counter(&profile->noval_local_counters[hash],
&shtag);
if (!cnt) {
lock_set_release(linker->profile->locks, hash);
lock_set_release(profile->locks, hash);
return -1;
}

cnt->n++;
} else {
linker->profile->noval_local_counters[hash] =
(void*)((long)linker->profile->noval_local_counters[hash] + 1);
profile->noval_local_counters[hash] =
(void *)((long)profile->noval_local_counters[hash] + 1);
}
}

lock_set_release( linker->profile->locks,hash );
lock_set_release(profile->locks, hash);
} else if (!is_replicated) {
if (!cdbc) {
LM_WARN("Cachedb not initialized yet - cannot update profile\n");
@@ -834,11 +833,11 @@ static int link_dlg_profile(struct dlg_profile_link *linker,
return -1;
}
/* prepare buffers */
if( linker->profile->has_value) {
if (profile->has_value) {

if (dlg_fill_value(&linker->profile->name, &linker->value) < 0)
if (dlg_fill_value(&profile->name, &linker->value) < 0)
return -1;
if (dlg_fill_size(&linker->profile->name) < 0)
if (dlg_fill_size(&profile->name) < 0)
return -1;

/* not really interested in the new val */
@@ -854,7 +853,7 @@ static int link_dlg_profile(struct dlg_profile_link *linker,
return -1;
}
} else {
if (dlg_fill_name(&linker->profile->name) < 0)
if (dlg_fill_name(&profile->name) < 0)
return -1;

if (cdbf.add(cdbc, &dlg_prof_noval_buf, 1,

0 comments on commit 0823297

Please sign in to comment.
You can’t perform that action at this time.