From 25e83d29f4558994f0f53f6415b96059e42e2c83 Mon Sep 17 00:00:00 2001 From: Christophe Jaillet Date: Sun, 20 Dec 2015 08:34:59 +0000 Subject: [PATCH] Use 'ap_array_str_contains' to simplify code. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1720996 13f79535-47bb-0310-9956-ffa450edef68 --- modules/http/http_protocol.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 25328d9dce..8d6263aca6 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -1584,8 +1584,6 @@ AP_DECLARE(void) ap_copy_method_list(ap_method_list_t *dest, 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 @@ -1596,18 +1594,13 @@ AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method) 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); } /* @@ -1616,9 +1609,7 @@ AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *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 @@ -1632,14 +1623,10 @@ AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method) /* * 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; }