]> granicus.if.org Git - apache/commitdiff
Modified ap_make_full_path to minimize the number of strlen operations
authorBrian Pane <brianp@apache.org>
Sun, 2 Dec 2001 05:09:51 +0000 (05:09 +0000)
committerBrian Pane <brianp@apache.org>
Sun, 2 Dec 2001 05:09:51 +0000 (05:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92280 13f79535-47bb-0310-9956-ffa450edef68

server/util.c

index 7eaa1dc041a2f235a763e4ec9cffb02efe9cc847..8b12f85216651411d2ceba11ebadb5f2f3011e17 100644 (file)
@@ -1692,16 +1692,26 @@ AP_DECLARE(int) ap_is_rdirectory(apr_pool_t *p, const char *path)
 AP_DECLARE(char *) ap_make_full_path(apr_pool_t *a, const char *src1,
                                  const char *src2)
 {
-    register int x;
-
-    x = strlen(src1);
-    if (x == 0)
-       return apr_pstrcat(a, "/", src2, NULL);
-
-    if (src1[x - 1] != '/')
-       return apr_pstrcat(a, src1, "/", src2, NULL);
-    else
-       return apr_pstrcat(a, src1, src2, NULL);
+    apr_size_t len1, len2;
+    char *path;
+
+    len1 = strlen(src1);
+    len2 = strlen(src2);
+    path = (char *)apr_palloc(a, len1 + len2 + 2); /* +2 for '/' plus null */
+    if (len1 == 0) {
+        *path = '/';
+        memcpy(path + 1, src2, len2 + 1);
+    }
+    else {
+        char *next;
+        memcpy(path, src1, len1);
+        next = path + len1;
+        if (next[-1] != '/') {
+            *next++ = '/';
+        }
+        memcpy(next, src2, len2 + 1);
+    }
+    return path;
 }
 
 /*