From a830be12030eb9cabe6e59be857916b75cb8a76d Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Sun, 2 Dec 2001 05:46:36 +0000 Subject: [PATCH] Reduced the number of strlen operations in ap_getword() git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92281 13f79535-47bb-0310-9956-ffa450edef68 --- server/util.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/server/util.c b/server/util.c index 8b12f85216..9de5a83916 100644 --- a/server/util.c +++ b/server/util.c @@ -642,21 +642,24 @@ AP_DECLARE(char *) ap_getword_nc(apr_pool_t *atrans, char **line, char stop) AP_DECLARE(char *) ap_getword(apr_pool_t *atrans, const char **line, char stop) { - const char *pos = ap_strchr_c(*line, stop); + const char *pos = *line; + int len; char *res; - if (!pos) { - res = apr_pstrdup(atrans, *line); - *line += strlen(*line); - return res; + while ((*pos != stop) && *pos) { + ++pos; } - res = apr_pstrndup(atrans, *line, pos - *line); + len = pos - *line; + res = (char *)apr_palloc(atrans, len + 1); + memcpy(res, *line, len); + res[len] = 0; - while (*pos == stop) { - ++pos; + if (stop) { + while (*pos == stop) { + ++pos; + } } - *line = pos; return res; -- 2.50.1