Use 'ap_array_str_contains' to simplify code.
Use 'ap_array_str_contains' to simplify code.
Use 'ap_array_str_contains' to simplify code.
Use 'ap_array_str_contains' to simplify code.
Submitted by: jailletc36
Reviewed/backported by: jim
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@
1725507 13f79535-47bb-0310-9956-
ffa450edef68
PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
[ start all new proposals below, under PATCHES PROPOSED. ]
- *) mod_negotiation: Use 'ap_array_str_contains' to simplify code.
- core: likewise
- http: likewise
- trunk patch: http://svn.apache.org/r1719252
- http://svn.apache.org/r1719254
- http://svn.apache.org/r1719255
- http://svn.apache.org/r1720996 (change in ap_method_in_list not
- tested, it is not actually used)
- 2.4.x patch: trunk works
- +1: jailletc36, covener, jim
-
*) mod_mod_authn_socache: Do not use the magic string "directory". Use the
corresponding global variable as in all other places of the module.
trunk patch: http://svn.apache.org/r1719257
AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method)
{
int methnum;
- int i;
- char **methods;
/*
* If it's one of our known methods, use the shortcut and check the
return !!(l->method_mask & (AP_METHOD_BIT << methnum));
}
/*
- * Otherwise, see if the method name is in the array or string names
+ * Otherwise, see if the method name is in the array of string names.
*/
if ((l->method_list == NULL) || (l->method_list->nelts == 0)) {
return 0;
}
- methods = (char **)l->method_list->elts;
- for (i = 0; i < l->method_list->nelts; ++i) {
- if (strcmp(method, methods[i]) == 0) {
- return 1;
- }
- }
- return 0;
+
+ return ap_array_str_contains(l->method_list, method);
}
/*
AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method)
{
int methnum;
- int i;
const char **xmethod;
- char **methods;
/*
* If it's one of our known methods, use the shortcut and use the
/*
* Otherwise, see if the method name is in the array of string names.
*/
- if (l->method_list->nelts != 0) {
- methods = (char **)l->method_list->elts;
- for (i = 0; i < l->method_list->nelts; ++i) {
- if (strcmp(method, methods[i]) == 0) {
- return;
- }
- }
+ if (ap_array_str_contains(l->method_list, method)) {
+ return;
}
+
xmethod = (const char **) apr_array_push(l->method_list);
*xmethod = method;
}
*/
static int variant_has_language(var_rec *variant, const char *lang)
{
- int j, max;
-
/* fast exit */
if ( !lang
- || !variant->content_languages
- || !(max = variant->content_languages->nelts)) {
+ || !variant->content_languages) {
return 0;
}
- for (j = 0; j < max; ++j) {
- if (!strcmp(lang,
- ((char **) (variant->content_languages->elts))[j])) {
- return 1;
- }
+ if (ap_array_str_contains(variant->content_languages, lang)) {
+ return 1;
}
return 0;
AP_DECLARE(int) ap_exists_config_define(const char *name)
{
- char **defines;
- int i;
-
- defines = (char **)ap_server_config_defines->elts;
- for (i = 0; i < ap_server_config_defines->nelts; i++) {
- if (strcmp(defines[i], name) == 0) {
- return 1;
- }
- }
-
- return 0;
+ return ap_array_str_contains(ap_server_config_defines, name);
}
static const char *start_ifdefine(cmd_parms *cmd, void *dummy, const char *arg)
const ap_expr_t *arg = e2->node_arg2;
ap_expr_list_func_t *func = (ap_expr_list_func_t *)info->node_arg1;
apr_array_header_t *haystack;
- int i = 0;
+
AP_DEBUG_ASSERT(func != NULL);
AP_DEBUG_ASSERT(info->node_op == op_ListFuncInfo);
haystack = (*func)(ctx, info->node_arg2, ap_expr_eval_word(ctx, arg));
- if (haystack == NULL)
+ if (haystack == NULL) {
return 0;
- for (; i < haystack->nelts; i++) {
- if (strcmp(needle, APR_ARRAY_IDX(haystack,i,char *)) == 0)
- return 1;
+ }
+ if (ap_array_str_contains(haystack, needle)) {
+ return 1;
}
}
return 0;