summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2005-02-22 00:24:13 (GMT)
committerIlia Alshanetsky <iliaa@php.net>2005-02-22 00:24:13 (GMT)
commitc7b931d80d7960040ab51f07f04d0d1e1f05525b (patch)
treecfd40030f6bd78b7257a183b7edebc8f735a2ad0 /main
parent498cce1f80a8f26558bca784b276ee4698e4b31b (diff)
downloadphp-c7b931d80d7960040ab51f07f04d0d1e1f05525b.tar.gz
Fixed bug #31515 (Improve performance of scandir() by factor of 10 or so).
Diffstat (limited to 'main')
-rwxr-xr-xmain/php_streams.h8
-rwxr-xr-xmain/streams/streams.c21
2 files changed, 14 insertions, 15 deletions
diff --git a/main/php_streams.h b/main/php_streams.h
index 36a0221..10fc248 100755
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -328,11 +328,11 @@ PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_
#define php_stream_closedir(dirstream) php_stream_close((dirstream))
#define php_stream_rewinddir(dirstream) php_stream_rewind((dirstream))
-PHPAPI int php_stream_dirent_alphasort(const php_stream_dirent **a, const php_stream_dirent **b);
-PHPAPI int php_stream_dirent_alphasortr(const php_stream_dirent **a, const php_stream_dirent **b);
+PHPAPI int php_stream_dirent_alphasort(const char **a, const char **b);
+PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b);
-PHPAPI int _php_stream_scandir(char *dirname, php_stream_dirent **namelist[], int flags, php_stream_context *context,
- int (*compare) (const php_stream_dirent **a, const php_stream_dirent **b) TSRMLS_DC);
+PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_stream_context *context,
+ int (*compare) (const char **a, const char **b) TSRMLS_DC);
#define php_stream_scandir(dirname, namelist, context, compare) _php_stream_scandir((dirname), (namelist), 0, (context), (compare) TSRMLS_CC)
PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC);
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 7d2700e..066662c 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -1944,28 +1944,28 @@ PHPAPI int php_stream_context_del_link(php_stream_context *context,
/* {{{ php_stream_dirent_alphasort
*/
-PHPAPI int php_stream_dirent_alphasort(const php_stream_dirent **a, const php_stream_dirent **b)
+PHPAPI int php_stream_dirent_alphasort(const char **a, const char **b)
{
- return strcoll((*a)->d_name,(*b)->d_name);
+ return strcoll(*a, *b);
}
/* }}} */
/* {{{ php_stream_dirent_alphasortr
*/
-PHPAPI int php_stream_dirent_alphasortr(const php_stream_dirent **a, const php_stream_dirent **b)
+PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b)
{
- return strcoll((*b)->d_name,(*a)->d_name);
+ return strcoll(*b, *a);
}
/* }}} */
/* {{{ php_stream_scandir
*/
-PHPAPI int _php_stream_scandir(char *dirname, php_stream_dirent **namelist[], int flags, php_stream_context *context,
- int (*compare) (const php_stream_dirent **a, const php_stream_dirent **b) TSRMLS_DC)
+PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_stream_context *context,
+ int (*compare) (const char **a, const char **b) TSRMLS_DC)
{
php_stream *stream;
php_stream_dirent sdp;
- php_stream_dirent **vector = NULL;
+ char **vector = NULL;
int vector_size = 0;
int nfiles = 0;
@@ -1985,11 +1985,10 @@ PHPAPI int _php_stream_scandir(char *dirname, php_stream_dirent **namelist[], in
} else {
vector_size *= 2;
}
- vector = (php_stream_dirent **) erealloc(vector, vector_size * sizeof(php_stream_dirent *));
+ vector = (char **) erealloc(vector, vector_size * sizeof(char *));
}
- vector[nfiles] = emalloc(sizeof(php_stream_dirent));
- memcpy(vector[nfiles], &sdp, sizeof(sdp));
+ vector[nfiles] = estrdup(sdp.d_name);
nfiles++;
}
@@ -1998,7 +1997,7 @@ PHPAPI int _php_stream_scandir(char *dirname, php_stream_dirent **namelist[], in
*namelist = vector;
if (compare) {
- qsort(*namelist, nfiles, sizeof(php_stream_dirent *), (int(*)(const void *, const void *))compare);
+ qsort(*namelist, nfiles, sizeof(char *), (int(*)(const void *, const void *))compare);
}
return nfiles;
}