]> granicus.if.org Git - apache/commitdiff
Reduced the number of strlen operations in ap_getword()
authorBrian Pane <brianp@apache.org>
Sun, 2 Dec 2001 05:46:36 +0000 (05:46 +0000)
committerBrian Pane <brianp@apache.org>
Sun, 2 Dec 2001 05:46:36 +0000 (05:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92281 13f79535-47bb-0310-9956-ffa450edef68

server/util.c

index 8b12f85216651411d2ceba11ebadb5f2f3011e17..9de5a8391622e669d9d46d467e1ad2dd5a1e3f1a 100644 (file)
@@ -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;