diff options
author | Dmitry Stogov <dmitry@zend.com> | 2017-10-31 18:51:35 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2017-10-31 18:51:35 +0300 |
commit | bbfd0df9d3903f1a5faa301e553de92372d70f03 (patch) | |
tree | 597ea731ee50ebe268d67e59425c2ef333831365 | |
parent | 5b044aacbeb481a840da9f9733dacfc3e0bf5cb7 (diff) | |
download | php-git-bbfd0df9d3903f1a5faa301e553de92372d70f03.tar.gz |
Use interned strings for persistent stream wrappers and filters
-rw-r--r-- | ext/opcache/ZendAccelerator.c | 15 | ||||
-rw-r--r-- | ext/standard/user_filters.c | 2 | ||||
-rw-r--r-- | main/php_streams.h | 4 | ||||
-rw-r--r-- | main/streams/filter.c | 9 | ||||
-rw-r--r-- | main/streams/php_stream_filter_api.h | 2 | ||||
-rw-r--r-- | main/streams/streams.c | 12 | ||||
-rw-r--r-- | main/streams/userspace.c | 11 |
7 files changed, 34 insertions, 21 deletions
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 260ecc9d2d..178f96f67e 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -549,6 +549,7 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int { uint32_t j; Bucket *p, *q; + HashTable *ht; /* empty string */ zend_empty_string = new_interned_string(zend_empty_string); @@ -680,6 +681,20 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int entry->orig_value = new_interned_string(entry->orig_value); } } ZEND_HASH_FOREACH_END(); + + ht = php_get_stream_filters_hash_global(); + ZEND_HASH_FOREACH_BUCKET(ht, p) { + if (p->key) { + p->key = new_interned_string(p->key); + } + } ZEND_HASH_FOREACH_END(); + + ht = php_stream_get_url_stream_wrappers_hash_global(); + ZEND_HASH_FOREACH_BUCKET(ht, p) { + if (p->key) { + p->key = new_interned_string(p->key); + } + } ZEND_HASH_FOREACH_END(); } static zend_string *accel_replace_string_by_shm_permanent(zend_string *str) diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index 4d9f4f5fbb..1f39464a97 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -587,7 +587,7 @@ PHP_FUNCTION(stream_filter_register) fdat->classname = zend_string_copy(classname); if (zend_hash_add_ptr(BG(user_filter_map), filtername, fdat) != NULL && - php_stream_filter_register_factory_volatile(ZSTR_VAL(filtername), &user_filter_factory) == SUCCESS) { + php_stream_filter_register_factory_volatile(filtername, &user_filter_factory) == SUCCESS) { RETVAL_TRUE; } else { zend_string_release(classname); diff --git a/main/php_streams.h b/main/php_streams.h index d10d087fb4..c268295933 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -563,8 +563,8 @@ PHP_RSHUTDOWN_FUNCTION(streams); BEGIN_EXTERN_C() PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper); PHPAPI int php_unregister_url_stream_wrapper(const char *protocol); -PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper); -PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol); +PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper); +PHPAPI int php_unregister_url_stream_wrapper_volatile(zend_string *protocol); PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC); PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options); PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf); diff --git a/main/streams/filter.c b/main/streams/filter.c index 6014a49661..5d8fccfca7 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -46,7 +46,8 @@ PHPAPI HashTable *_php_get_stream_filters_hash(void) /* API for registering GLOBAL filters */ PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory) { - return zend_hash_str_add_ptr(&stream_filters_hash, filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE; + zend_string *str = zend_string_init_interned(filterpattern, strlen(filterpattern), 1); + return zend_hash_add_ptr(&stream_filters_hash, str, factory) ? SUCCESS : FAILURE; } PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern) @@ -55,15 +56,15 @@ PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern) } /* API for registering VOLATILE wrappers */ -PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory) +PHPAPI int php_stream_filter_register_factory_volatile(zend_string *filterpattern, php_stream_filter_factory *factory) { if (!FG(stream_filters)) { ALLOC_HASHTABLE(FG(stream_filters)); - zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash), NULL, NULL, 0); + zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash) + 1, NULL, NULL, 0); zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL); } - return zend_hash_str_add_ptr(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE; + return zend_hash_add_ptr(FG(stream_filters), filterpattern, factory) ? SUCCESS : FAILURE; } /* Buckets */ diff --git a/main/streams/php_stream_filter_api.h b/main/streams/php_stream_filter_api.h index c109ca9993..ad9c541f1d 100644 --- a/main/streams/php_stream_filter_api.h +++ b/main/streams/php_stream_filter_api.h @@ -148,7 +148,7 @@ typedef struct _php_stream_filter_factory { BEGIN_EXTERN_C() PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory); PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern); -PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory); +PHPAPI int php_stream_filter_register_factory_volatile(zend_string *filterpattern, php_stream_filter_factory *factory); PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, uint8_t persistent); END_EXTERN_C() diff --git a/main/streams/streams.c b/main/streams/streams.c index 15cecff377..7f130fcb15 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1691,11 +1691,9 @@ static void clone_wrapper_hash(void) } /* API for registering VOLATILE wrappers */ -PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper) +PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper) { - unsigned int protocol_len = (unsigned int)strlen(protocol); - - if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) { + if (php_stream_wrapper_scheme_validate(ZSTR_VAL(protocol), ZSTR_LEN(protocol)) == FAILURE) { return FAILURE; } @@ -1703,16 +1701,16 @@ PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_st clone_wrapper_hash(); } - return zend_hash_str_add_ptr(FG(stream_wrappers), protocol, protocol_len, wrapper) ? SUCCESS : FAILURE; + return zend_hash_add_ptr(FG(stream_wrappers), protocol, wrapper) ? SUCCESS : FAILURE; } -PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol) +PHPAPI int php_unregister_url_stream_wrapper_volatile(zend_string *protocol) { if (!FG(stream_wrappers)) { clone_wrapper_hash(); } - return zend_hash_str_del(FG(stream_wrappers), protocol, strlen(protocol)); + return zend_hash_del(FG(stream_wrappers), protocol); } /* }}} */ diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 2b838c6ddc..81ce3d0e19 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -514,7 +514,7 @@ PHP_FUNCTION(stream_wrapper_register) rsrc = zend_register_resource(uwrap, le_protocols); if ((uwrap->ce = zend_lookup_class(classname)) != NULL) { - if (php_register_url_stream_wrapper_volatile(ZSTR_VAL(protocol), &uwrap->wrapper) == SUCCESS) { + if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper) == SUCCESS) { RETURN_TRUE; } else { /* We failed. But why? */ @@ -538,10 +538,9 @@ PHP_FUNCTION(stream_wrapper_register) Unregister a wrapper for the life of the current request. */ PHP_FUNCTION(stream_wrapper_unregister) { - char *protocol; - size_t protocol_len; + zend_string *protocol; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &protocol, &protocol_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &protocol) == FAILURE) { RETURN_FALSE; } @@ -579,9 +578,9 @@ PHP_FUNCTION(stream_wrapper_restore) } /* A failure here could be okay given that the protocol might have been merely unregistered */ - php_unregister_url_stream_wrapper_volatile(ZSTR_VAL(protocol)); + php_unregister_url_stream_wrapper_volatile(protocol); - if (php_register_url_stream_wrapper_volatile(ZSTR_VAL(protocol), wrapper) == FAILURE) { + if (php_register_url_stream_wrapper_volatile(protocol, wrapper) == FAILURE) { php_error_docref(NULL, E_WARNING, "Unable to restore original %s:// wrapper", ZSTR_VAL(protocol)); RETURN_FALSE; } |