summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2007-05-16 23:16:51 +0000
committerMarcus Boerger <helly@php.net>2007-05-16 23:16:51 +0000
commit5e3af23d204c0b29448cb78c46e9c5271633494f (patch)
tree6cdf983ca16da4adb1054316182c2e85014757b7 /ext
parent6365d3e06a7b96ef4b69697a0d5fd89bbc272ce3 (diff)
downloadphp-git-5e3af23d204c0b29448cb78c46e9c5271633494f.tar.gz
- Reduce overhead of Phar's RINIT
Diffstat (limited to 'ext')
-rw-r--r--ext/phar/TODO2
-rw-r--r--ext/phar/phar.c35
-rwxr-xr-xext/phar/phar_internal.h3
-rwxr-xr-xext/phar/phar_object.c1
4 files changed, 33 insertions, 8 deletions
diff --git a/ext/phar/TODO b/ext/phar/TODO
index 1cefffc91a..9734c02fbe 100644
--- a/ext/phar/TODO
+++ b/ext/phar/TODO
@@ -48,8 +48,8 @@ Version 1.2.0
X add preliminary phar command (phar.php) [Marcus]
X add phar command (phar.phar) [Marcus]
X list all available compression methods using Phar::getSupportedCompression() [Marcus]
+ X Reduce RINIT to variable initialization, no fcall, hashinit [Marcus]
- * Reduce RINIT to variable initialization, no fcall, hashinit
* Provide an additional header that allows better compatibility with PHP 4
__HALT_COMPILER();function __HALT_COMPILER(){}$a=<<<PHARDATABEGIN\n
* ability to have Phar object return file class as offsetGet() result
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index a317950a4a..fcc40a34b5 100644
--- a/ext/phar/phar.c
+++ b/ext/phar/phar.c
@@ -289,6 +289,8 @@ static int phar_get_archive(phar_archive_data **archive, char *fname, int fname_
{
phar_archive_data *fd, **fd_ptr;
+ phar_request_initialize(TSRMLS_C);
+
if (error) {
*error = NULL;
}
@@ -1147,6 +1149,7 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int
mydata->sig_flags = sig_flags;
mydata->sig_len = sig_len;
mydata->signature = signature;
+ phar_request_initialize(TSRMLS_C);
zend_hash_add(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, (void*)&mydata, sizeof(phar_archive_data*), NULL);
if (register_alias) {
mydata->is_explicit_alias = 1;
@@ -1240,6 +1243,7 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al
} else {
register_alias = 1;
}
+ phar_request_initialize(TSRMLS_C);
zend_hash_add(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, (void*)&mydata, sizeof(phar_archive_data*), NULL);
if (register_alias) {
zend_hash_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, (void*)&mydata, sizeof(phar_archive_data*), NULL);
@@ -1675,6 +1679,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, char *pat
}
host_len = strlen(resource->host);
+ phar_request_initialize(TSRMLS_C);
if (zend_hash_find(&(PHAR_GLOBALS->phar_plain_map), resource->host, host_len+1, (void **)&plain_map) == SUCCESS) {
spprintf(&internal_file, 0, "%s%s", plain_map, resource->path);
fp = php_stream_open_wrapper_ex(internal_file, mode, options, opened_path, context);
@@ -2847,6 +2852,7 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, char *url, int flags,
}
host_len = strlen(resource->host);
+ phar_request_initialize(TSRMLS_C);
if (zend_hash_find(&(PHAR_GLOBALS->phar_plain_map), resource->host, host_len+1, (void **)&plain_map) == SUCCESS) {
spprintf(&internal_file, 0, "%s%s", plain_map, resource->path);
retval = php_stream_stat_path_ex(internal_file, flags, ssb, context);
@@ -3099,6 +3105,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio
}
host_len = strlen(resource->host);
+ phar_request_initialize(TSRMLS_C);
if (zend_hash_find(&(PHAR_GLOBALS->phar_plain_map), resource->host, host_len+1, (void **)&plain_map) == SUCCESS) {
spprintf(&internal_file, 0, "%s%s", plain_map, resource->path);
retval = php_stream_unlink(internal_file, options, context);
@@ -3217,6 +3224,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char
}
host_len = strlen(resource_from->host);
+ phar_request_initialize(TSRMLS_C);
if (zend_hash_find(&(PHAR_GLOBALS->phar_plain_map), resource_from->host, host_len+1, (void **)&plain_map) == SUCCESS) {
/*TODO:use php_stream_rename() once available*/
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot rename \"%s\" to \"%s\" from extracted phar archive", url_from, url_to);
@@ -3349,6 +3357,7 @@ static php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, char *path
}
host_len = strlen(resource->host);
+ phar_request_initialize(TSRMLS_C);
if (zend_hash_find(&(PHAR_GLOBALS->phar_plain_map), resource->host, host_len+1, (void **)&plain_map) == SUCCESS) {
spprintf(&internal_file, 0, "%s%s", plain_map, resource->path);
ret = php_stream_opendir(internal_file, options, context);
@@ -3455,20 +3464,32 @@ PHP_RINIT_FUNCTION(phar) /* {{{ */
{
PHAR_GLOBALS->request_done = 0;
PHAR_GLOBALS->request_ends = 0;
- zend_hash_init(&(PHAR_GLOBALS->phar_fname_map), sizeof(phar_archive_data*), zend_get_hash_value, destroy_phar_data, 0);
- zend_hash_init(&(PHAR_GLOBALS->phar_alias_map), sizeof(phar_archive_data*), zend_get_hash_value, NULL, 0);
- zend_hash_init(&(PHAR_GLOBALS->phar_plain_map), sizeof(const char *), zend_get_hash_value, NULL, 0);
- phar_split_extract_list(TSRMLS_C);
+ PHAR_GLOBALS->request_init = 0;
return SUCCESS;
}
+
+void phar_request_initialize(TSRMLS_D) /* {{{ */
+{
+ if (!PHAR_GLOBALS->request_init)
+ {
+ PHAR_GLOBALS->request_init = 1;
+ zend_hash_init(&(PHAR_GLOBALS->phar_fname_map), sizeof(phar_archive_data*), zend_get_hash_value, destroy_phar_data, 0);
+ zend_hash_init(&(PHAR_GLOBALS->phar_alias_map), sizeof(phar_archive_data*), zend_get_hash_value, NULL, 0);
+ zend_hash_init(&(PHAR_GLOBALS->phar_plain_map), sizeof(const char *), zend_get_hash_value, NULL, 0);
+ phar_split_extract_list(TSRMLS_C);
+ }
+}
/* }}} */
PHP_RSHUTDOWN_FUNCTION(phar) /* {{{ */
{
PHAR_GLOBALS->request_ends = 1;
- zend_hash_destroy(&(PHAR_GLOBALS->phar_alias_map));
- zend_hash_destroy(&(PHAR_GLOBALS->phar_fname_map));
- zend_hash_destroy(&(PHAR_GLOBALS->phar_plain_map));
+ if (PHAR_GLOBALS->request_init)
+ {
+ zend_hash_destroy(&(PHAR_GLOBALS->phar_alias_map));
+ zend_hash_destroy(&(PHAR_GLOBALS->phar_fname_map));
+ zend_hash_destroy(&(PHAR_GLOBALS->phar_plain_map));
+ }
PHAR_GLOBALS->request_done = 1;
return SUCCESS;
}
diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h
index 1cfbc0cf19..2cf6aa5dfb 100755
--- a/ext/phar/phar_internal.h
+++ b/ext/phar/phar_internal.h
@@ -107,6 +107,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phar)
int readonly;
zend_bool readonly_orig;
zend_bool require_hash_orig;
+ int request_init;
int require_hash;
int request_done;
int request_ends;
@@ -223,6 +224,8 @@ union _phar_entry_object {
BEGIN_EXTERN_C()
+void phar_request_initialize(TSRMLS_D);
+
void phar_object_init(TSRMLS_D);
int phar_open_filename(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error TSRMLS_DC);
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index 85b39762a1..99edb54df6 100755
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -45,6 +45,7 @@ PHP_METHOD(Phar, getExtractList)
{
array_init(return_value);
+ phar_request_initialize(TSRMLS_C);
zend_hash_apply_with_arguments(&PHAR_G(phar_plain_map), phar_get_extract_list, 1, return_value);
}
/* }}} */