cellog          Sun Jun 15 23:00:47 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/phar   phar.c phar.phar 
  Log:
  minor performance improvement
  
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.c?r1=1.370.2.18&r2=1.370.2.19&diff_format=u
Index: php-src/ext/phar/phar.c
diff -u php-src/ext/phar/phar.c:1.370.2.18 php-src/ext/phar/phar.c:1.370.2.19
--- php-src/ext/phar/phar.c:1.370.2.18  Sun Jun 15 21:42:19 2008
+++ php-src/ext/phar/phar.c     Sun Jun 15 23:00:46 2008
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: phar.c,v 1.370.2.18 2008/06/15 21:42:19 cellog Exp $ */
+/* $Id: phar.c,v 1.370.2.19 2008/06/15 23:00:46 cellog Exp $ */
 
 #define PHAR_MAIN 1
 #include "phar_internal.h"
@@ -1894,74 +1894,84 @@
  */
 char *phar_fix_filepath(char *path, int *new_len, int use_cwd TSRMLS_DC) /* 
{{{ */
 {
+       char newpath[MAXPATHLEN];
+       int newpath_len;
        char *ptr, *free_path, *new_phar;
        char *tok;
        int ptr_length, new_phar_len = 1, path_length = *new_len;
 
        if (PHAR_G(cwd_len) && use_cwd && path_length > 2 && path[0] == '.' && 
path[1] == '/') {
-               free_path = path;
-               new_phar_len = PHAR_G(cwd_len);
-               new_phar = estrndup(PHAR_G(cwd), new_phar_len);
+               newpath_len = PHAR_G(cwd_len);
+               memcpy(newpath, PHAR_G(cwd), newpath_len);
        } else {
-               free_path = path;
-               new_phar = estrndup("/\0", 2);
+               newpath[0] = '/';
+               newpath_len = 1;
+       }
+       ptr = path;
+       if (*ptr == '/') ++ptr;
+       tok = ptr;
+       do {
+               ptr = memchr(ptr, '/', path_length - (ptr - path));
+       } while (ptr && ptr - tok == 0 && *ptr == '/' && ++ptr && ++tok);
+       if (!ptr && (path_length - (tok - path))) {
+               switch (path_length - (tok - path)) {
+                       case 1 :
+                               if (*tok == '.') {
+                                       efree(path);
+                                       *new_len = 1;
+                                       return estrndup("/", 1);
+                               }
+                               break;
+                       case 2 :
+                               if (tok[0] == '.' && tok[1] == '.') {
+                                       efree(path);
+                                       *new_len = 1;
+                                       return estrndup("/", 1);
+                               }
+               }
+               return path;
        }
-       tok = NULL;
-       ptr = tsrm_strtok_r(path, "/", &tok);
        while (ptr) {
-               ptr_length = strlen(ptr);
-
-               if (IS_DIRECTORY_UP(ptr, ptr_length)) {
-                       char save;
-
-                       save = '/';
-
-#define PREVIOUS new_phar[new_phar_len - 1]
-
-                       while (new_phar_len > 1 &&
-                                       !IS_BACKSLASH(PREVIOUS)) {
-                               save = PREVIOUS;
-                               PREVIOUS = '\0';
-                               new_phar_len--;
-                       }
-
-                       if (new_phar[0] != '/') {
-                               new_phar[new_phar_len++] = save;
-                               new_phar[new_phar_len] = '\0';
-                       } else if (new_phar_len > 1) {
-                               PREVIOUS = '\0';
-                               new_phar_len--;
-                       }
-               } else if (!IS_DIRECTORY_CURRENT(ptr, ptr_length)) {
-                       if (new_phar_len > 1) {
-                               new_phar = (char *) erealloc(new_phar, 
new_phar_len+ptr_length+1+1);
-                               new_phar[new_phar_len++] = '/';
-                               memcpy(&new_phar[new_phar_len], ptr, 
ptr_length+1);
+               ptr_length = ptr - tok;
+last_time:
+               if (IS_DIRECTORY_UP(tok, ptr_length)) {
+#define PREVIOUS newpath[newpath_len - 1]
+
+                       while (newpath_len > 1 && !IS_BACKSLASH(PREVIOUS)) {
+                               newpath_len--;
+                       }
+
+                       if (newpath[0] != '/') {
+                               newpath[newpath_len] = '\0';
+                       } else if (newpath_len > 1) {
+                               --newpath_len;
+                       }
+               } else if (!IS_DIRECTORY_CURRENT(tok, ptr_length)) {
+                       if (newpath_len > 1) {
+                               newpath[newpath_len++] = '/';
+                               memcpy(newpath + newpath_len, tok, 
ptr_length+1);
                        } else {
-                               new_phar = (char *) erealloc(new_phar, 
new_phar_len+ptr_length+1);
-                               memcpy(&new_phar[new_phar_len], ptr, 
ptr_length+1);
+                               memcpy(newpath + newpath_len, tok, 
ptr_length+1);
                        }
 
-                       new_phar_len += ptr_length;
+                       newpath_len += ptr_length;
+               }
+               if (ptr == path + path_length) {
+                       break;
+               }
+               tok = ++ptr;
+               do {
+                       ptr = memchr(ptr, '/', path_length - (ptr - path));
+               } while (ptr && ptr - tok == 0 && *ptr == '/' && ++ptr && 
++tok);
+               if (!ptr && (path_length - (tok - path))) {
+                       ptr_length = path_length - (tok - path);
+                       ptr = path + path_length;
+                       goto last_time;
                }
-               ptr = tsrm_strtok_r(NULL, "/", &tok);
-       }
-
-       if (path[path_length-1] == '/' && new_phar_len > 1) {
-               new_phar = (char*)erealloc(new_phar, new_phar_len + 2);
-               new_phar[new_phar_len++] = '/';
-               new_phar[new_phar_len] = 0;
-       }
-
-       efree(free_path);
-
-       if (new_phar_len == 0) {
-               new_phar = (char *) erealloc(new_phar, new_phar_len+1+1);
-               new_phar[new_phar_len] = '/';
-               new_phar[++new_phar_len] = '\0';
        }
-       *new_len = new_phar_len;
-       return new_phar;
+       efree(path);
+       *new_len = newpath_len;
+       return estrndup(newpath, newpath_len);
 }
 /* }}} */
 
@@ -3398,7 +3408,7 @@
        php_info_print_table_header(2, "Phar: PHP Archive support", "enabled");
        php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION);
        php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION);
-       php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.18 $");
+       php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.19 $");
        php_info_print_table_row(2, "Phar-based phar archives", "enabled");
        php_info_print_table_row(2, "Tar-based phar archives", "enabled");
        php_info_print_table_row(2, "ZIP-based phar archives", "enabled");
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.phar?r1=1.7.2.17&r2=1.7.2.18&diff_format=u
Index: php-src/ext/phar/phar.phar



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to