Skip to content

Commit 13e4ce3

Browse files
committed
Improve SPL directory and stat() cache using zend_srting* instead of char*
1 parent 5e8ae15 commit 13e4ce3

File tree

13 files changed

+274
-286
lines changed

13 files changed

+274
-286
lines changed

ext/phar/phar_object.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,6 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
14431443
case IS_OBJECT:
14441444
if (instanceof_function(Z_OBJCE_P(value), spl_ce_SplFileInfo)) {
14451445
char *test = NULL;
1446-
zval dummy;
14471446
spl_filesystem_object *intern = (spl_filesystem_object*)((char*)Z_OBJ_P(value) - Z_OBJ_P(value)->handlers->offset);
14481447

14491448
if (!base_len) {
@@ -1455,9 +1454,7 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
14551454
case SPL_FS_DIR:
14561455
test = spl_filesystem_object_get_path(intern, NULL);
14571456
fname_len = spprintf(&fname, 0, "%s%c%s", test, DEFAULT_SLASH, intern->u.dir.entry.d_name);
1458-
php_stat(fname, fname_len, FS_IS_DIR, &dummy);
1459-
1460-
if (Z_TYPE(dummy) == IS_TRUE) {
1457+
if (php_stream_stat_path(fname, &ssb) == 0 && S_ISDIR(ssb.sb.st_mode)) {
14611458
/* ignore directories */
14621459
efree(fname);
14631460
return ZEND_HASH_APPLY_KEEP;
@@ -1478,7 +1475,7 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
14781475
goto phar_spl_fileinfo;
14791476
case SPL_FS_INFO:
14801477
case SPL_FS_FILE:
1481-
fname = expand_filepath(intern->file_name, NULL);
1478+
fname = expand_filepath(ZSTR_VAL(intern->file_name), NULL);
14821479
if (!fname) {
14831480
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Could not resolve file path");
14841481
return ZEND_HASH_APPLY_STOP;
@@ -4644,11 +4641,11 @@ PHP_METHOD(PharFileInfo, chmod)
46444641
/* hackish cache in php_stat needs to be cleared */
46454642
/* if this code fails to work, check main/streams/streams.c, _php_stream_stat_path */
46464643
if (BG(CurrentLStatFile)) {
4647-
efree(BG(CurrentLStatFile));
4644+
zend_string_release(BG(CurrentLStatFile));
46484645
}
46494646

46504647
if (BG(CurrentStatFile)) {
4651-
efree(BG(CurrentStatFile));
4648+
zend_string_release(BG(CurrentStatFile));
46524649
}
46534650

46544651
BG(CurrentLStatFile) = NULL;

0 commit comments

Comments
 (0)