diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-09-12 15:53:40 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-09-12 15:53:40 +0000 |
commit | 6fa2c158ccddb95d834c53ca65ed99fe05d65d0d (patch) | |
tree | ab0bb6556221099db14cc3182de61550d1b6d546 /utils | |
parent | 5769779bfb0402950f00c172a95c222571762ec6 (diff) |
Change the traversal to use ao2_callback() instead of an ao2_iterator. Using
ao2_callback() is a much more efficient way of performing an operation on every
item in the container. This change makes hashtest2 run in about 25% of the
time it ran before on my system.
In general, I would say that it makes the most sense to use an ao2_iterator if
the operation being performed is going to take a long time and you don't want
to keep the container locked while you work with each object. Otherwise,
the use of ao2_callback is preferred.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@82282 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'utils')
-rw-r--r-- | utils/hashtest2.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/utils/hashtest2.c b/utils/hashtest2.c index 9bd883143..2e3bc410d 100644 --- a/utils/hashtest2.c +++ b/utils/hashtest2.c @@ -148,16 +148,17 @@ static void add_element(void) els_added++; /* unprotected, sometimes off, but, not really important, either */ } +static int do_nothing_cb(void *obj, void *arg, int flags) +{ + return 0; +} + static void traverse_elements(void) { - struct ht_element *el; - struct ao2_iterator it = ao2_iterator_init(glob_hashtab, 0); #ifdef DEBUG printf("Traverse hashtab\n"); #endif - while ((el = ao2_iterator_next(&it))) { - ao2_ref(el,-1); - } + ao2_callback(glob_hashtab, OBJ_NODATA, do_nothing_cb, NULL); els_traversals++; /* unprotected, sometimes off, but, not really important, either */ } |