dmitry          Fri Nov 10 11:20:48 2006 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src    NEWS 
    /php-src/win32      readdir.c readdir.h 
    /TSRM       readdir.h 
    /php-src/main       reentrancy.c 
  Log:
  opendir() is reimplemented using GetFistFile/GetNextFile those are faster 
then _findfirst/_findnext
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.346&r2=1.2027.2.547.2.347&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.346 php-src/NEWS:1.2027.2.547.2.347
--- php-src/NEWS:1.2027.2.547.2.346     Fri Nov 10 10:55:26 2006
+++ php-src/NEWS        Fri Nov 10 11:20:47 2006
@@ -3,6 +3,8 @@
 ?? ??? 2007, PHP 5.2.1
 - Windows related optimizations (Dmitry, Stas)
   . removed unnecessary checks for ISREG file and corresponding stat() calls
+  . opendir() is reimplemented using GetFistFile/GetNextFile those are faster
+    then _findfirst/_findnext
 - Zend Memory Manager Improvements (Dmitry)
   . use HeapAlloc() instead of VirtualAlloc()
   . use "win32" storage manager (instead of "malloc") on Windows by default
http://cvs.php.net/viewvc.cgi/php-src/win32/readdir.c?r1=1.11&r2=1.11.6.1&diff_format=u
Index: php-src/win32/readdir.c
diff -u php-src/win32/readdir.c:1.11 php-src/win32/readdir.c:1.11.6.1
--- php-src/win32/readdir.c:1.11        Wed Jun  9 14:18:14 2004
+++ php-src/win32/readdir.c     Fri Nov 10 11:20:47 2006
@@ -2,8 +2,8 @@
 #include <string.h>
 #include <errno.h>
 
-#include "readdir.h"
 #include "php.h"
+#include "readdir.h"
 
 /**********************************************************************
  * Implement dirent-style opendir/readdir/rewinddir/closedir on Win32
@@ -23,14 +23,14 @@
 {
        DIR *dp;
        char *filespec;
-       long handle;
+       HANDLE handle;
        int index;
 
-       filespec = malloc(strlen(dir) + 2 + 1);
+       filespec = (char *)malloc(strlen(dir) + 2 + 1);
        strcpy(filespec, dir);
        index = strlen(filespec) - 1;
        if (index >= 0 && (filespec[index] == '/' || 
-          (filespec[index] == '\\' && !IsDBCSLeadByte(filespec[index-1]))))
+          (filespec[index] == '\\' && (index == 0 || 
!IsDBCSLeadByte(filespec[index-1])))))
                filespec[index] = '\0';
        strcat(filespec, "/*");
 
@@ -38,8 +38,9 @@
        dp->offset = 0;
        dp->finished = 0;
 
-       if ((handle = _findfirst(filespec, &(dp->fileinfo))) < 0) {
-               if (errno == ENOENT) {
+       if ((handle = FindFirstFile(filespec, &(dp->fileinfo))) == 
INVALID_HANDLE_VALUE) {
+               DWORD err = GetLastError();
+               if (err == ERROR_NO_MORE_FILES) {
                        dp->finished = 1;
                } else {
                        free(dp);
@@ -60,14 +61,14 @@
                return NULL;
 
        if (dp->offset != 0) {
-               if (_findnext(dp->handle, &(dp->fileinfo)) < 0) {
+               if (FindNextFile(dp->handle, &(dp->fileinfo)) == 0) {
                        dp->finished = 1;
                        return NULL;
                }
        }
        dp->offset++;
 
-       strlcpy(dp->dent.d_name, dp->fileinfo.name, _MAX_FNAME+1);
+       strlcpy(dp->dent.d_name, dp->fileinfo.cFileName, _MAX_FNAME+1);
        dp->dent.d_ino = 1;
        dp->dent.d_reclen = strlen(dp->dent.d_name);
        dp->dent.d_off = dp->offset;
@@ -83,7 +84,7 @@
        }
 
        if (dp->offset != 0) {
-               if (_findnext(dp->handle, &(dp->fileinfo)) < 0) {
+               if (FindNextFile(dp->handle, &(dp->fileinfo)) == 0) {
                        dp->finished = 1;
                        *result = NULL;
                        return 0;
@@ -91,7 +92,7 @@
        }
        dp->offset++;
 
-       strlcpy(dp->dent.d_name, dp->fileinfo.name, _MAX_FNAME+1);
+       strlcpy(dp->dent.d_name, dp->fileinfo.cFileName, _MAX_FNAME+1);
        dp->dent.d_ino = 1;
        dp->dent.d_reclen = strlen(dp->dent.d_name);
        dp->dent.d_off = dp->offset;
@@ -107,7 +108,7 @@
 {
        if (!dp)
                return 0;
-       _findclose(dp->handle);
+       FindClose(dp->handle);
        if (dp->dir)
                free(dp->dir);
        if (dp)
@@ -120,27 +121,28 @@
 {
        /* Re-set to the beginning */
        char *filespec;
-       long handle;
+       HANDLE handle;
        int index;
 
-       _findclose(dp->handle);
+       FindClose(dp->handle);
 
        dp->offset = 0;
        dp->finished = 0;
 
-       filespec = malloc(strlen(dp->dir) + 2 + 1);
+       filespec = (char *)malloc(strlen(dp->dir) + 2 + 1);
        strcpy(filespec, dp->dir);
        index = strlen(filespec) - 1;
-       if (index >= 0 && (filespec[index] == '/' || filespec[index] == '\\'))
+       if (index >= 0 && (filespec[index] == '/' || 
+          (filespec[index] == '\\' && (index == 0 || 
!IsDBCSLeadByte(filespec[index-1])))))
                filespec[index] = '\0';
        strcat(filespec, "/*");
 
-       if ((handle = _findfirst(filespec, &(dp->fileinfo))) < 0) {
-               if (errno == ENOENT)
-                       dp->finished = 1;
-               }
+       if ((handle = FindFirstFile(filespec, &(dp->fileinfo))) == 
INVALID_HANDLE_VALUE) {
+               dp->finished = 1;
+       }
+       
        dp->handle = handle;
        free(filespec);
 
-return 0;
+       return 0;
 }
http://cvs.php.net/viewvc.cgi/php-src/win32/readdir.h?r1=1.8&r2=1.8.6.1&diff_format=u
Index: php-src/win32/readdir.h
diff -u php-src/win32/readdir.h:1.8 php-src/win32/readdir.h:1.8.6.1
--- php-src/win32/readdir.h:1.8 Mon Jan 27 20:39:30 2003
+++ php-src/win32/readdir.h     Fri Nov 10 11:20:47 2006
@@ -7,11 +7,15 @@
  * on Windows 95/NT.
  */
 
+#define _WIN32_WINNT 0x0400
+
+#include <windows.h>
+
 #include <io.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
-
+#include <direct.h>
 
 /* struct dirent - same as Unix */
 
@@ -25,10 +29,10 @@
 
 /* typedef DIR - not the same as Unix */
 typedef struct {
-       long handle;                            /* _findfirst/_findnext handle 
*/
+       HANDLE handle;                          /* _findfirst/_findnext handle 
*/
        short offset;                           /* offset into directory */
        short finished;                         /* 1 if there are not more 
files */
-       struct _finddata_t fileinfo;    /* from _findfirst/_findnext */
+       WIN32_FIND_DATA fileinfo;       /* from _findfirst/_findnext */
        char *dir;                                      /* the dir we are 
reading */
        struct dirent dent;                     /* the dirent to return */
 } DIR;
http://cvs.php.net/viewvc.cgi/TSRM/readdir.h?r1=1.1&r2=1.1.34.1&diff_format=u
Index: TSRM/readdir.h
diff -u TSRM/readdir.h:1.1 TSRM/readdir.h:1.1.34.1
--- TSRM/readdir.h:1.1  Sun Sep  3 18:47:35 2000
+++ TSRM/readdir.h      Fri Nov 10 11:20:47 2006
@@ -7,11 +7,15 @@
  * on Windows 95/NT.
  */
 
+#define _WIN32_WINNT 0x0400
+
+#include <windows.h>
+
 #include <io.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
-
+#include <direct.h>
 
 /* struct dirent - same as Unix */
 
@@ -25,10 +29,10 @@
 
 /* typedef DIR - not the same as Unix */
 typedef struct {
-       long handle;                            /* _findfirst/_findnext handle 
*/
+       HANDLE handle;                          /* _findfirst/_findnext handle 
*/
        short offset;                           /* offset into directory */
        short finished;                         /* 1 if there are not more 
files */
-       struct _finddata_t fileinfo;    /* from _findfirst/_findnext */
+       WIN32_FIND_DATA fileinfo;       /* from _findfirst/_findnext */
        char *dir;                                      /* the dir we are 
reading */
        struct dirent dent;                     /* the dirent to return */
 } DIR;
@@ -38,7 +42,6 @@
 struct dirent *readdir(DIR *);
 int readdir_r(DIR *, struct dirent *, struct dirent **);
 int closedir(DIR *);
-void rewinddir(DIR *);
-
+int rewinddir(DIR *);
 
 #endif /* READDIR_H */
http://cvs.php.net/viewvc.cgi/php-src/main/reentrancy.c?r1=1.43.2.1&r2=1.43.2.1.2.1&diff_format=u
Index: php-src/main/reentrancy.c
diff -u php-src/main/reentrancy.c:1.43.2.1 
php-src/main/reentrancy.c:1.43.2.1.2.1
--- php-src/main/reentrancy.c:1.43.2.1  Sun Jan  1 12:50:17 2006
+++ php-src/main/reentrancy.c   Fri Nov 10 11:20:48 2006
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: reentrancy.c,v 1.43.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: reentrancy.c,v 1.43.2.1.2.1 2006/11/10 11:20:48 dmitry Exp $ */
 
 #include <sys/types.h>
 #include <string.h>
@@ -25,10 +25,6 @@
 #include <dirent.h>
 #endif
 
-#ifdef PHP_WIN32
-#include "win32/readdir.h"
-#endif
-
 #include "php_reentrancy.h"
 #include "ext/standard/php_rand.h"                   /* for PHP_RAND_MAX */
 

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

Reply via email to