mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Use ZEND_TLS for spl (#7043)
For extension globals that do not require cross-module visibility, we can use ZEND_TLS as a more efficient TLS mechanism.
This commit is contained in:
parent
97a849602d
commit
82ccd47d39
@ -43,18 +43,11 @@
|
||||
ZEND_GET_MODULE(spl)
|
||||
#endif
|
||||
|
||||
ZEND_DECLARE_MODULE_GLOBALS(spl)
|
||||
ZEND_TLS zend_string *spl_autoload_extensions;
|
||||
ZEND_TLS HashTable *spl_autoload_functions;
|
||||
|
||||
#define SPL_DEFAULT_FILE_EXTENSIONS ".inc,.php"
|
||||
|
||||
/* {{{ PHP_GINIT_FUNCTION */
|
||||
static PHP_GINIT_FUNCTION(spl)
|
||||
{
|
||||
spl_globals->autoload_extensions = NULL;
|
||||
spl_globals->autoload_functions = NULL;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static zend_class_entry * spl_find_ce_by_name(zend_string *name, bool autoload)
|
||||
{
|
||||
zend_class_entry *ce;
|
||||
@ -307,7 +300,7 @@ PHP_FUNCTION(spl_autoload)
|
||||
}
|
||||
|
||||
if (!file_exts) {
|
||||
file_exts = SPL_G(autoload_extensions);
|
||||
file_exts = spl_autoload_extensions;
|
||||
}
|
||||
|
||||
if (file_exts == NULL) { /* autoload_extensions is not initialized, set to defaults */
|
||||
@ -345,17 +338,17 @@ PHP_FUNCTION(spl_autoload_extensions)
|
||||
}
|
||||
|
||||
if (file_exts) {
|
||||
if (SPL_G(autoload_extensions)) {
|
||||
zend_string_release_ex(SPL_G(autoload_extensions), 0);
|
||||
if (spl_autoload_extensions) {
|
||||
zend_string_release_ex(spl_autoload_extensions, 0);
|
||||
}
|
||||
SPL_G(autoload_extensions) = zend_string_copy(file_exts);
|
||||
spl_autoload_extensions = zend_string_copy(file_exts);
|
||||
}
|
||||
|
||||
if (SPL_G(autoload_extensions) == NULL) {
|
||||
if (spl_autoload_extensions == NULL) {
|
||||
RETURN_STRINGL(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1);
|
||||
} else {
|
||||
zend_string_addref(SPL_G(autoload_extensions));
|
||||
RETURN_STR(SPL_G(autoload_extensions));
|
||||
zend_string_addref(spl_autoload_extensions);
|
||||
RETURN_STR(spl_autoload_extensions);
|
||||
}
|
||||
} /* }}} */
|
||||
|
||||
@ -413,17 +406,17 @@ static bool autoload_func_info_equals(
|
||||
}
|
||||
|
||||
static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_string *lc_name) {
|
||||
if (!SPL_G(autoload_functions)) {
|
||||
if (!spl_autoload_functions) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We don't use ZEND_HASH_FOREACH here,
|
||||
* because autoloaders may be added/removed during autoloading. */
|
||||
HashPosition pos;
|
||||
zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &pos);
|
||||
zend_hash_internal_pointer_reset_ex(spl_autoload_functions, &pos);
|
||||
while (1) {
|
||||
autoload_func_info *alfi =
|
||||
zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &pos);
|
||||
zend_hash_get_current_data_ptr_ex(spl_autoload_functions, &pos);
|
||||
if (!alfi) {
|
||||
break;
|
||||
}
|
||||
@ -451,7 +444,7 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri
|
||||
}
|
||||
}
|
||||
|
||||
zend_hash_move_forward_ex(SPL_G(autoload_functions), &pos);
|
||||
zend_hash_move_forward_ex(spl_autoload_functions, &pos);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -480,12 +473,12 @@ PHP_FUNCTION(spl_autoload_call)
|
||||
} while (0)
|
||||
|
||||
static Bucket *spl_find_registered_function(autoload_func_info *find_alfi) {
|
||||
if (!SPL_G(autoload_functions)) {
|
||||
if (!spl_autoload_functions) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
autoload_func_info *alfi;
|
||||
ZEND_HASH_FOREACH_PTR(SPL_G(autoload_functions), alfi) {
|
||||
ZEND_HASH_FOREACH_PTR(spl_autoload_functions, alfi) {
|
||||
if (autoload_func_info_equals(alfi, find_alfi)) {
|
||||
return _p;
|
||||
}
|
||||
@ -514,11 +507,11 @@ PHP_FUNCTION(spl_autoload_register)
|
||||
"spl_autoload_register() will always throw");
|
||||
}
|
||||
|
||||
if (!SPL_G(autoload_functions)) {
|
||||
ALLOC_HASHTABLE(SPL_G(autoload_functions));
|
||||
zend_hash_init(SPL_G(autoload_functions), 1, NULL, autoload_func_info_zval_dtor, 0);
|
||||
if (!spl_autoload_functions) {
|
||||
ALLOC_HASHTABLE(spl_autoload_functions);
|
||||
zend_hash_init(spl_autoload_functions, 1, NULL, autoload_func_info_zval_dtor, 0);
|
||||
/* Initialize as non-packed hash table for prepend functionality. */
|
||||
zend_hash_real_init_mixed(SPL_G(autoload_functions));
|
||||
zend_hash_real_init_mixed(spl_autoload_functions);
|
||||
}
|
||||
|
||||
/* If first arg is not null */
|
||||
@ -558,10 +551,10 @@ PHP_FUNCTION(spl_autoload_register)
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
zend_hash_next_index_insert_ptr(SPL_G(autoload_functions), alfi);
|
||||
if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) {
|
||||
zend_hash_next_index_insert_ptr(spl_autoload_functions, alfi);
|
||||
if (prepend && spl_autoload_functions->nNumOfElements > 1) {
|
||||
/* Move the newly created element to the head of the hashtable */
|
||||
HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions));
|
||||
HT_MOVE_TAIL_TO_HEAD(spl_autoload_functions);
|
||||
}
|
||||
|
||||
RETURN_TRUE;
|
||||
@ -580,7 +573,7 @@ PHP_FUNCTION(spl_autoload_unregister)
|
||||
if (fcc.function_handler && zend_string_equals_literal(
|
||||
fcc.function_handler->common.function_name, "spl_autoload_call")) {
|
||||
/* Don't destroy the hash table, as we might be iterating over it right now. */
|
||||
zend_hash_clean(SPL_G(autoload_functions));
|
||||
zend_hash_clean(spl_autoload_functions);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
@ -588,7 +581,7 @@ PHP_FUNCTION(spl_autoload_unregister)
|
||||
Bucket *p = spl_find_registered_function(alfi);
|
||||
autoload_func_info_destroy(alfi);
|
||||
if (p) {
|
||||
zend_hash_del_bucket(SPL_G(autoload_functions), p);
|
||||
zend_hash_del_bucket(spl_autoload_functions, p);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
@ -605,8 +598,8 @@ PHP_FUNCTION(spl_autoload_functions)
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
if (SPL_G(autoload_functions)) {
|
||||
ZEND_HASH_FOREACH_PTR(SPL_G(autoload_functions), alfi) {
|
||||
if (spl_autoload_functions) {
|
||||
ZEND_HASH_FOREACH_PTR(spl_autoload_functions, alfi) {
|
||||
if (alfi->closure) {
|
||||
GC_ADDREF(alfi->closure);
|
||||
add_next_index_object(return_value, alfi->closure);
|
||||
@ -723,21 +716,21 @@ PHP_MINIT_FUNCTION(spl)
|
||||
|
||||
PHP_RINIT_FUNCTION(spl) /* {{{ */
|
||||
{
|
||||
SPL_G(autoload_extensions) = NULL;
|
||||
SPL_G(autoload_functions) = NULL;
|
||||
spl_autoload_extensions = NULL;
|
||||
spl_autoload_functions = NULL;
|
||||
return SUCCESS;
|
||||
} /* }}} */
|
||||
|
||||
PHP_RSHUTDOWN_FUNCTION(spl) /* {{{ */
|
||||
{
|
||||
if (SPL_G(autoload_extensions)) {
|
||||
zend_string_release_ex(SPL_G(autoload_extensions), 0);
|
||||
SPL_G(autoload_extensions) = NULL;
|
||||
if (spl_autoload_extensions) {
|
||||
zend_string_release_ex(spl_autoload_extensions, 0);
|
||||
spl_autoload_extensions = NULL;
|
||||
}
|
||||
if (SPL_G(autoload_functions)) {
|
||||
zend_hash_destroy(SPL_G(autoload_functions));
|
||||
FREE_HASHTABLE(SPL_G(autoload_functions));
|
||||
SPL_G(autoload_functions) = NULL;
|
||||
if (spl_autoload_functions) {
|
||||
zend_hash_destroy(spl_autoload_functions);
|
||||
FREE_HASHTABLE(spl_autoload_functions);
|
||||
spl_autoload_functions = NULL;
|
||||
}
|
||||
return SUCCESS;
|
||||
} /* }}} */
|
||||
@ -753,10 +746,6 @@ zend_module_entry spl_module_entry = {
|
||||
PHP_RSHUTDOWN(spl),
|
||||
PHP_MINFO(spl),
|
||||
PHP_SPL_VERSION,
|
||||
PHP_MODULE_GLOBALS(spl),
|
||||
PHP_GINIT(spl),
|
||||
NULL,
|
||||
NULL,
|
||||
STANDARD_MODULE_PROPERTIES_EX
|
||||
STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
/* }}} */
|
||||
|
@ -50,15 +50,6 @@ PHP_RINIT_FUNCTION(spl);
|
||||
PHP_RSHUTDOWN_FUNCTION(spl);
|
||||
PHP_MINFO_FUNCTION(spl);
|
||||
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(spl)
|
||||
zend_string *autoload_extensions;
|
||||
HashTable *autoload_functions;
|
||||
ZEND_END_MODULE_GLOBALS(spl)
|
||||
|
||||
ZEND_EXTERN_MODULE_GLOBALS(spl)
|
||||
#define SPL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(spl, v)
|
||||
|
||||
PHPAPI zend_string *php_spl_object_hash(zend_object *obj);
|
||||
|
||||
#endif /* PHP_SPL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user