[asterisk-dev] ast_category_root is the same as ast_variable_browse!
Luigi Rizzo
rizzo at icir.org
Wed Nov 14 09:33:41 CST 2007
the two functions in main/config.c
ast_category_root() and ast_variable_browse() do the same thing: given
a config file and string representing a category name, both
return a pointer to the first variable in the category.
If there is a difference, it is that ast_variable_browse() has an
optimization (but probably a broken one) to avoid scanning the
list of categories on repeated searches: if you look at the
line marked "--->" below, the comparison is made just on the
pointer and not on the content of the string.
struct ast_variable *ast_variable_browse(const struct ast_config *config, const char *category)
{
struct ast_category *cat = NULL;
---> if (category && config->last_browse && (config->last_browse->name == category))
cat = config->last_browse;
else
cat = ast_category_get(config, category);
return (cat) ? cat->root : NULL;
}
Given that there is no point for having two identical functions,
i would like to first remove ast_category_root() which is the least
used one (only one instance in chan_sip.c) and later have a look
again at the implementation of the cache
(config->last_browse) to at least document the behaviour and
verify if there is any ill side effect.
cheers
luigi
More information about the asterisk-dev
mailing list