diff options
author | Greg Beaver <cellog@php.net> | 2008-06-20 05:42:58 +0000 |
---|---|---|
committer | Greg Beaver <cellog@php.net> | 2008-06-20 05:42:58 +0000 |
commit | 7cc6b9f3f58c59d051319fc4f4b7f35bdc514951 (patch) | |
tree | 3a1f2dedeeb20c04bee3902f35be05e8e4e74288 /ext/phar/func_interceptors.c | |
parent | 5233505043e8fd6b2f73a29c2c7a8148b5c651a4 (diff) | |
download | php-git-7cc6b9f3f58c59d051319fc4f4b7f35bdc514951.tar.gz |
making progress - up to 42/phar vs. 48/disk with these optimizations
Diffstat (limited to 'ext/phar/func_interceptors.c')
-rw-r--r-- | ext/phar/func_interceptors.c | 115 |
1 files changed, 53 insertions, 62 deletions
diff --git a/ext/phar/func_interceptors.c b/ext/phar/func_interceptors.c index 0abc623963..026f88fd5d 100644 --- a/ext/phar/func_interceptors.c +++ b/ext/phar/func_interceptors.c @@ -119,7 +119,7 @@ PHAR_FUNC(phar_file_get_contents) /* {{{ */ fname_len = strlen(fname); if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, 2, 0 TSRMLS_CC)) { char *name; - phar_archive_data **pphar; + phar_archive_data *phar; efree(entry); entry = filename; @@ -133,8 +133,7 @@ PHAR_FUNC(phar_file_get_contents) /* {{{ */ } /* retrieving a file defaults to within the current directory, so use this if possible */ - if ((PHAR_GLOBALS->phar_fname_map.arBuckets && FAILURE == (zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar))) - && (PHAR_G(manifest_cached) && FAILURE == (zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar)))) { + if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) { efree(arch); goto skip_phar; } @@ -150,7 +149,7 @@ PHAR_FUNC(phar_file_get_contents) /* {{{ */ } else { entry = phar_fix_filepath(estrndup(entry, entry_len), &entry_len, 1 TSRMLS_CC); if (entry[0] == '/') { - if (!zend_hash_exists(&((*pphar)->manifest), entry + 1, entry_len - 1)) { + if (!zend_hash_exists(&(phar->manifest), entry + 1, entry_len - 1)) { /* this file is not in the phar, use the original path */ notfound: efree(arch); @@ -158,7 +157,7 @@ notfound: goto skip_phar; } } else { - if (!zend_hash_exists(&((*pphar)->manifest), entry, entry_len)) { + if (!zend_hash_exists(&(phar->manifest), entry, entry_len)) { goto notfound; } } @@ -237,7 +236,7 @@ PHAR_FUNC(phar_readfile) /* {{{ */ int arch_len, entry_len, fname_len; php_stream_context *context = NULL; char *name; - phar_archive_data **pphar; + phar_archive_data *phar; fname = zend_get_executed_filename(TSRMLS_C); if (strncasecmp(fname, "phar://", 7)) { @@ -253,8 +252,7 @@ PHAR_FUNC(phar_readfile) /* {{{ */ /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */ entry_len = filename_len; /* retrieving a file defaults to within the current directory, so use this if possible */ - if ((PHAR_GLOBALS->phar_fname_map.arBuckets && FAILURE == (zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar))) - && (PHAR_G(manifest_cached) && FAILURE == (zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar)))) { + if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) { efree(arch); goto skip_phar; } @@ -269,7 +267,7 @@ PHAR_FUNC(phar_readfile) /* {{{ */ } else { entry = phar_fix_filepath(estrndup(entry, entry_len), &entry_len, 1 TSRMLS_CC); if (entry[0] == '/') { - if (!zend_hash_exists(&((*pphar)->manifest), entry + 1, entry_len - 1)) { + if (!zend_hash_exists(&(phar->manifest), entry + 1, entry_len - 1)) { /* this file is not in the phar, use the original path */ notfound: efree(entry); @@ -277,7 +275,7 @@ notfound: goto skip_phar; } } else { - if (!zend_hash_exists(&((*pphar)->manifest), entry, entry_len)) { + if (!zend_hash_exists(&(phar->manifest), entry, entry_len)) { goto notfound; } } @@ -330,7 +328,7 @@ PHAR_FUNC(phar_fopen) /* {{{ */ int arch_len, entry_len, fname_len; php_stream_context *context = NULL; char *name; - phar_archive_data **pphar; + phar_archive_data *phar; fname = zend_get_executed_filename(TSRMLS_C); if (strncasecmp(fname, "phar://", 7)) { @@ -346,8 +344,7 @@ PHAR_FUNC(phar_fopen) /* {{{ */ /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */ entry_len = filename_len; /* retrieving a file defaults to within the current directory, so use this if possible */ - if ((PHAR_GLOBALS->phar_fname_map.arBuckets && FAILURE == (zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar))) - && (PHAR_G(manifest_cached) && FAILURE == (zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar)))) { + if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) { efree(arch); goto skip_phar; } @@ -362,7 +359,7 @@ PHAR_FUNC(phar_fopen) /* {{{ */ } else { entry = phar_fix_filepath(estrndup(entry, entry_len), &entry_len, 1 TSRMLS_CC); if (entry[0] == '/') { - if (!zend_hash_exists(&((*pphar)->manifest), entry + 1, entry_len - 1)) { + if (!zend_hash_exists(&(phar->manifest), entry + 1, entry_len - 1)) { /* this file is not in the phar, use the original path */ notfound: efree(entry); @@ -370,7 +367,7 @@ notfound: goto skip_phar; } } else { - if (!zend_hash_exists(&((*pphar)->manifest), entry, entry_len)) { + if (!zend_hash_exists(&(phar->manifest), entry, entry_len)) { /* this file is not in the phar, use the original path */ goto notfound; } @@ -602,8 +599,7 @@ void phar_file_stat(const char *filename, php_stat_len filename_length, int type int arch_len, entry_len, fname_len; struct stat sb = {0}; phar_entry_info *data = NULL; - char *tmp; - int tmp_len; + phar_archive_data *phar; fname = zend_get_executed_filename(TSRMLS_C); @@ -614,31 +610,39 @@ void phar_file_stat(const char *filename, php_stat_len filename_length, int type goto skip_phar; } fname_len = strlen(fname); + if (PHAR_G(last_phar) && fname_len - 7 >= PHAR_G(last_phar_name_len) && !memcmp(fname + 7, PHAR_G(last_phar_name), PHAR_G(last_phar_name_len))) { + arch = estrndup(PHAR_G(last_phar_name), PHAR_G(last_phar_name_len)); + arch_len = PHAR_G(last_phar_name_len); + entry = estrndup(filename, filename_length); + /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */ + entry_len = (int) filename_length; + phar = PHAR_G(last_phar); + goto splitted; + } if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, 2, 0 TSRMLS_CC)) { - phar_archive_data **pphar; efree(entry); entry = estrndup(filename, filename_length); /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */ entry_len = (int) filename_length; - if ((PHAR_GLOBALS->phar_fname_map.arBuckets && FAILURE == (zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar))) - && (PHAR_G(manifest_cached) && FAILURE == (zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar)))) { + if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) { efree(arch); goto skip_phar; } +splitted: entry = phar_fix_filepath(entry, &entry_len, 1 TSRMLS_CC); if (entry[0] == '/') { - if (SUCCESS == zend_hash_find(&((*pphar)->manifest), entry + 1, entry_len - 1, (void **) &data)) { + if (SUCCESS == zend_hash_find(&(phar->manifest), entry + 1, entry_len - 1, (void **) &data)) { efree(entry); goto stat_entry; } goto notfound; } - if (SUCCESS == zend_hash_find(&((*pphar)->manifest), entry, entry_len, (void **) &data)) { + if (SUCCESS == zend_hash_find(&(phar->manifest), entry, entry_len, (void **) &data)) { efree(entry); goto stat_entry; } - if (SUCCESS == zend_hash_find(&((*pphar)->virtual_dirs), entry, entry_len, (void **) &data)) { + if (SUCCESS == zend_hash_find(&(phar->virtual_dirs), entry, entry_len, (void **) &data)) { efree(entry); efree(arch); if (IS_EXISTS_CHECK(type)) { @@ -648,13 +652,13 @@ void phar_file_stat(const char *filename, php_stat_len filename_length, int type sb.st_mode = 0777; sb.st_mode |= S_IFDIR; /* regular directory */ #ifdef NETWARE - sb.st_mtime.tv_sec = (*pphar)->max_timestamp; - sb.st_atime.tv_sec = (*pphar)->max_timestamp; - sb.st_ctime.tv_sec = (*pphar)->max_timestamp; + sb.st_mtime.tv_sec = phar->max_timestamp; + sb.st_atime.tv_sec = phar->max_timestamp; + sb.st_ctime.tv_sec = phar->max_timestamp; #else - sb.st_mtime = (*pphar)->max_timestamp; - sb.st_atime = (*pphar)->max_timestamp; - sb.st_ctime = (*pphar)->max_timestamp; + sb.st_mtime = phar->max_timestamp; + sb.st_atime = phar->max_timestamp; + sb.st_ctime = phar->max_timestamp; #endif goto statme_baby; } else { @@ -675,7 +679,7 @@ notfound: PHAR_G(cwd_len) = 0; /* clean path without cwd */ entry = phar_fix_filepath(entry, &entry_len, 1 TSRMLS_CC); - if (SUCCESS == zend_hash_find(&((*pphar)->manifest), entry + 1, entry_len - 1, (void **) &data)) { + if (SUCCESS == zend_hash_find(&(phar->manifest), entry + 1, entry_len - 1, (void **) &data)) { PHAR_G(cwd) = save; PHAR_G(cwd_len) = save_len; efree(entry); @@ -685,7 +689,7 @@ notfound: } goto stat_entry; } - if (SUCCESS == zend_hash_find(&((*pphar)->virtual_dirs), entry + 1, entry_len - 1, (void **) &data)) { + if (SUCCESS == zend_hash_find(&(phar->virtual_dirs), entry + 1, entry_len - 1, (void **) &data)) { PHAR_G(cwd) = save; PHAR_G(cwd_len) = save_len; efree(entry); @@ -698,13 +702,13 @@ notfound: sb.st_mode = 0777; sb.st_mode |= S_IFDIR; /* regular directory */ #ifdef NETWARE - sb.st_mtime.tv_sec = (*pphar)->max_timestamp; - sb.st_atime.tv_sec = (*pphar)->max_timestamp; - sb.st_ctime.tv_sec = (*pphar)->max_timestamp; + sb.st_mtime.tv_sec = phar->max_timestamp; + sb.st_atime.tv_sec = phar->max_timestamp; + sb.st_ctime.tv_sec = phar->max_timestamp; #else - sb.st_mtime = (*pphar)->max_timestamp; - sb.st_atime = (*pphar)->max_timestamp; - sb.st_ctime = (*pphar)->max_timestamp; + sb.st_mtime = phar->max_timestamp; + sb.st_atime = phar->max_timestamp; + sb.st_ctime = phar->max_timestamp; #endif goto statme_baby; } @@ -759,29 +763,18 @@ stat_entry: statme_baby: efree(arch); - if (!(*pphar)->is_writeable) { + if (!phar->is_writeable) { sb.st_mode = (sb.st_mode & 0555) | (sb.st_mode & ~0777); } sb.st_nlink = 1; sb.st_rdev = -1; - if (data) { - tmp_len = data->filename_len + (*pphar)->alias_len; - } else { - tmp_len = (*pphar)->alias_len + 1; - } - tmp = (char *) emalloc(tmp_len); - memcpy(tmp, (*pphar)->alias, (*pphar)->alias_len); - if (data) { - memcpy(tmp + (*pphar)->alias_len, data->filename, data->filename_len); - } else { - *(tmp + (*pphar)->alias_len) = '/'; - } /* this is only for APC, so use /dev/null device - no chance of conflict there! */ sb.st_dev = 0xc; /* generate unique inode number for alias/filename, so no phars will conflict */ - sb.st_ino = (unsigned short)zend_get_hash_value(tmp, tmp_len); - efree(tmp); + if (data) { + sb.st_ino = data->inode; + } #ifndef PHP_WIN32 sb.st_blksize = -1; sb.st_blocks = -1; @@ -904,20 +897,19 @@ PHAR_FUNC(phar_is_file) /* {{{ */ } fname_len = strlen(fname); if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, 2, 0 TSRMLS_CC)) { - phar_archive_data **pphar; + phar_archive_data *phar; efree(entry); entry = filename; /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */ entry_len = filename_len; /* retrieving a file within the current directory, so use this if possible */ - if ((PHAR_GLOBALS->phar_fname_map.arBuckets && SUCCESS == (zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar))) - || (PHAR_G(manifest_cached) && SUCCESS == (zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar)))) { + if (SUCCESS == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) { phar_entry_info *etemp; entry = phar_fix_filepath(estrndup(entry, entry_len), &entry_len, 1 TSRMLS_CC); if (entry[0] == '/') { - if (SUCCESS == zend_hash_find(&((*pphar)->manifest), entry + 1, entry_len - 1, (void **) &etemp)) { + if (SUCCESS == zend_hash_find(&(phar->manifest), entry + 1, entry_len - 1, (void **) &etemp)) { /* this file is not in the current directory, use the original path */ found_it: efree(entry); @@ -925,7 +917,7 @@ found_it: RETURN_BOOL(!etemp->is_dir); } } else { - if (SUCCESS == zend_hash_find(&((*pphar)->manifest), entry, entry_len, (void **) &etemp)) { + if (SUCCESS == zend_hash_find(&(phar->manifest), entry, entry_len, (void **) &etemp)) { goto found_it; } } @@ -966,20 +958,19 @@ PHAR_FUNC(phar_is_link) /* {{{ */ } fname_len = strlen(fname); if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, 2, 0 TSRMLS_CC)) { - phar_archive_data **pphar; + phar_archive_data *phar; efree(entry); entry = filename; /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */ entry_len = filename_len; /* retrieving a file within the current directory, so use this if possible */ - if ((PHAR_GLOBALS->phar_fname_map.arBuckets && SUCCESS == (zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar))) - || (PHAR_G(manifest_cached) && SUCCESS == (zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar)))) { + if (SUCCESS == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) { phar_entry_info *etemp; entry = phar_fix_filepath(estrndup(entry, entry_len), &entry_len, 1 TSRMLS_CC); if (entry[0] == '/') { - if (SUCCESS == zend_hash_find(&((*pphar)->manifest), entry + 1, entry_len - 1, (void **) &etemp)) { + if (SUCCESS == zend_hash_find(&(phar->manifest), entry + 1, entry_len - 1, (void **) &etemp)) { /* this file is not in the current directory, use the original path */ found_it: efree(entry); @@ -987,7 +978,7 @@ found_it: RETURN_BOOL(etemp->link); } } else { - if (SUCCESS == zend_hash_find(&((*pphar)->manifest), entry, entry_len, (void **) &etemp)) { + if (SUCCESS == zend_hash_find(&(phar->manifest), entry, entry_len, (void **) &etemp)) { goto found_it; } } |