mirror of
https://github.com/php/php-src.git
synced 2024-11-27 03:44:07 +08:00
Avoid unnecessry reallocations
This commit is contained in:
parent
8ddda2f649
commit
6b2ed577fd
@ -522,7 +522,8 @@ ZEND_API int zend_delete_global_variable(zend_string *name TSRMLS_DC);
|
||||
ZEND_API void zend_rebuild_symbol_table(TSRMLS_D);
|
||||
ZEND_API void zend_attach_symbol_table(TSRMLS_D);
|
||||
ZEND_API void zend_detach_symbol_table(TSRMLS_D);
|
||||
ZEND_API int zend_set_local_var(const char *name, int len, zval *value, int force TSRMLS_DC);
|
||||
ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force TSRMLS_DC);
|
||||
ZEND_API int zend_set_local_var_str(const char *name, int len, zval *value, int force TSRMLS_DC);
|
||||
|
||||
ZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
|
||||
ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);
|
||||
|
@ -1885,7 +1885,7 @@ static int add_constant_info(zval *item, void *arg TSRMLS_DC)
|
||||
}
|
||||
|
||||
ZVAL_DUP(&const_val, &constant->value);
|
||||
add_assoc_zval_ex(name_array, constant->name->val, constant->name->len, &const_val);
|
||||
zend_hash_update(Z_ARRVAL_P(name_array), constant->name, &const_val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1969,7 +1969,7 @@ ZEND_FUNCTION(get_defined_constants)
|
||||
|
||||
ZVAL_DUP_DEREF(&const_val, &val->value);
|
||||
|
||||
add_assoc_zval_ex(&modules[module_number], val->name->val, val->name->len, &const_val);
|
||||
zend_hash_update(Z_ARRVAL(modules[module_number]), val->name, &const_val);
|
||||
next_constant:
|
||||
zend_hash_move_forward_ex(EG(zend_constants), &pos);
|
||||
}
|
||||
|
@ -1762,7 +1762,40 @@ ZEND_API void zend_detach_symbol_table(TSRMLS_D) /* {{{ */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
ZEND_API int zend_set_local_var(const char *name, int len, zval *value, int force TSRMLS_DC) /* {{{ */
|
||||
ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
if (!EG(active_symbol_table)) {
|
||||
int i;
|
||||
zend_execute_data *execute_data = EG(current_execute_data);
|
||||
zend_op_array *op_array = execute_data->op_array;
|
||||
zend_ulong h = STR_HASH_VAL(name);
|
||||
|
||||
if (op_array) {
|
||||
for (i = 0; i < op_array->last_var; i++) {
|
||||
if (op_array->vars[i]->h == h &&
|
||||
op_array->vars[i]->len == name->len &&
|
||||
memcmp(op_array->vars[i]->val, name->val, name->len) == 0) {
|
||||
ZVAL_COPY_VALUE(EX_VAR_NUM(i), value);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (force) {
|
||||
zend_rebuild_symbol_table(TSRMLS_C);
|
||||
if (EG(active_symbol_table)) {
|
||||
zend_hash_update(&EG(active_symbol_table)->ht, name, value);
|
||||
}
|
||||
} else {
|
||||
return FAILURE;
|
||||
}
|
||||
} else {
|
||||
return (zend_hash_update_ind(&EG(active_symbol_table)->ht, name, value) != NULL) ? SUCCESS : FAILURE;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
ZEND_API int zend_set_local_var_str(const char *name, int len, zval *value, int force TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
if (!EG(active_symbol_table)) {
|
||||
int i;
|
||||
|
@ -3387,8 +3387,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value
|
||||
zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC);
|
||||
}
|
||||
|
||||
//??? add_assoc_zval(return_value, key, &prop_copy);
|
||||
add_assoc_zval(return_value, key->val, &prop_copy);
|
||||
zend_hash_update(Z_ARRVAL_P(return_value), key, &prop_copy);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
@ -4369,8 +4368,7 @@ ZEND_METHOD(reflection_class, getInterfaces)
|
||||
for (i=0; i < ce->num_interfaces; i++) {
|
||||
zval interface;
|
||||
zend_reflection_class_factory(ce->interfaces[i], &interface TSRMLS_CC);
|
||||
//???
|
||||
add_assoc_zval_ex(return_value, ce->interfaces[i]->name->val, ce->interfaces[i]->name->len, &interface);
|
||||
zend_hash_update(Z_ARRVAL_P(return_value), ce->interfaces[i]->name, &interface);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4416,8 +4414,7 @@ ZEND_METHOD(reflection_class, getTraits)
|
||||
for (i=0; i < ce->num_traits; i++) {
|
||||
zval trait;
|
||||
zend_reflection_class_factory(ce->traits[i], &trait TSRMLS_CC);
|
||||
//???
|
||||
add_assoc_zval_ex(return_value, ce->traits[i]->name->val, ce->traits[i]->name->len, &trait);
|
||||
zend_hash_update(Z_ARRVAL_P(return_value), ce->traits[i]->name, &trait);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
@ -5249,8 +5246,7 @@ ZEND_METHOD(reflection_extension, getFunctions)
|
||||
if (fptr->common.type==ZEND_INTERNAL_FUNCTION
|
||||
&& fptr->internal_function.module == module) {
|
||||
reflection_function_factory(fptr, NULL, &function TSRMLS_CC);
|
||||
//???
|
||||
add_assoc_zval(return_value, fptr->common.function_name->val, &function);
|
||||
zend_hash_update(Z_ARRVAL_P(return_value), fptr->common.function_name, &function);
|
||||
}
|
||||
zend_hash_move_forward_ex(CG(function_table), &iterator);
|
||||
}
|
||||
@ -5266,9 +5262,7 @@ static int _addconstant(zval *el TSRMLS_DC, int num_args, va_list args, zend_has
|
||||
|
||||
if (number == constant->module_number) {
|
||||
ZVAL_DUP(&const_val, &constant->value);
|
||||
//??? INIT_PZVAL(const_val);
|
||||
|
||||
add_assoc_zval_ex(retval, constant->name->val, constant->name->len, &const_val);
|
||||
zend_hash_update(Z_ARRVAL_P(retval), constant->name, &const_val);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -5327,19 +5321,19 @@ ZEND_METHOD(reflection_extension, getINIEntries)
|
||||
/* }}} */
|
||||
|
||||
/* {{{ add_extension_class */
|
||||
static int add_extension_class(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
|
||||
static int add_extension_class(zval *zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
|
||||
{
|
||||
zend_class_entry *ce = Z_PTR_P(zv);
|
||||
zval *class_array = va_arg(args, zval*), zclass;
|
||||
struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*);
|
||||
int add_reflection_class = va_arg(args, int);
|
||||
|
||||
if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) {
|
||||
if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module && !strcasecmp(ce->info.internal.module->name, module->name)) {
|
||||
if (add_reflection_class) {
|
||||
zend_reflection_class_factory(*pce, &zclass TSRMLS_CC);
|
||||
//???
|
||||
add_assoc_zval_ex(class_array, (*pce)->name->val, (*pce)->name->len, &zclass);
|
||||
zend_reflection_class_factory(ce, &zclass TSRMLS_CC);
|
||||
zend_hash_update(Z_ARRVAL_P(class_array), ce->name, &zclass);
|
||||
} else {
|
||||
add_next_index_str(class_array, STR_COPY((*pce)->name));
|
||||
add_next_index_str(class_array, STR_COPY(ce->name));
|
||||
}
|
||||
}
|
||||
return ZEND_HASH_APPLY_KEEP;
|
||||
|
@ -1202,7 +1202,7 @@ static void spl_multiple_iterator_get_all(spl_SplObjectStorage *intern, int get_
|
||||
add_index_zval(return_value, Z_LVAL(element->inf), &retval);
|
||||
break;
|
||||
case IS_STRING:
|
||||
add_assoc_zval_ex(return_value, Z_STRVAL(element->inf), Z_STRLEN(element->inf), &retval);
|
||||
zend_hash_update(Z_ARRVAL_P(return_value), Z_STR(element->inf), &retval);
|
||||
break;
|
||||
default:
|
||||
zval_ptr_dtor(&retval);
|
||||
|
@ -1433,7 +1433,7 @@ PHP_FUNCTION(extract)
|
||||
}
|
||||
} else {
|
||||
ZVAL_DUP(&data, entry);
|
||||
zend_set_local_var(Z_STRVAL(final_name), Z_STRLEN(final_name), &data, 1 TSRMLS_CC);
|
||||
zend_set_local_var(Z_STR(final_name), &data, 1 TSRMLS_CC);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
@ -2685,13 +2685,13 @@ PHP_FUNCTION(array_column)
|
||||
Z_ADDREF_P(zcolval);
|
||||
}
|
||||
if (zkeyval && Z_TYPE_P(zkeyval) == IS_STRING) {
|
||||
add_assoc_zval(return_value, Z_STRVAL_P(zkeyval), zcolval);
|
||||
zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(zkeyval), zcolval);
|
||||
} else if (zkeyval && Z_TYPE_P(zkeyval) == IS_LONG) {
|
||||
add_index_zval(return_value, Z_LVAL_P(zkeyval), zcolval);
|
||||
} else if (zkeyval && Z_TYPE_P(zkeyval) == IS_OBJECT) {
|
||||
SEPARATE_ZVAL(zkeyval);
|
||||
convert_to_string(zkeyval);
|
||||
add_assoc_zval(return_value, Z_STRVAL_P(zkeyval), zcolval);
|
||||
zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(zkeyval), zcolval);
|
||||
} else {
|
||||
add_next_index_zval(return_value, zcolval);
|
||||
}
|
||||
@ -4492,8 +4492,7 @@ PHP_FUNCTION(array_map)
|
||||
add_next_index_zval(return_value, &result);
|
||||
} else {
|
||||
if (key_type == HASH_KEY_IS_STRING) {
|
||||
//???
|
||||
add_assoc_zval_ex(return_value, str_key->val, str_key->len, &result);
|
||||
zend_hash_update(Z_ARRVAL_P(return_value), str_key, &result);
|
||||
} else {
|
||||
add_index_zval(return_value, num_key, &result);
|
||||
}
|
||||
@ -4588,8 +4587,7 @@ PHP_FUNCTION(array_chunk)
|
||||
key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &str_key, &num_key, 0, &pos);
|
||||
switch (key_type) {
|
||||
case HASH_KEY_IS_STRING:
|
||||
//???
|
||||
add_assoc_zval_ex(&chunk, str_key->val, str_key->len, entry);
|
||||
zend_hash_update(Z_ARRVAL(chunk), str_key, entry);
|
||||
break;
|
||||
default:
|
||||
add_index_zval(&chunk, num_key, entry);
|
||||
@ -4661,8 +4659,7 @@ PHP_FUNCTION(array_combine)
|
||||
}
|
||||
|
||||
zval_add_ref(entry_values);
|
||||
//???
|
||||
add_assoc_zval_ex(return_value, Z_STRVAL_P(key_ptr), Z_STRLEN_P(key_ptr), entry_values);
|
||||
zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(key_ptr), entry_values);
|
||||
|
||||
if (key_ptr != entry_keys) {
|
||||
zval_dtor(&key);
|
||||
|
@ -4592,7 +4592,7 @@ static int add_config_entry_cb(zval *entry TSRMLS_DC, int num_args, va_list args
|
||||
} else if (Z_TYPE_P(entry) == IS_ARRAY) {
|
||||
array_init(&tmp);
|
||||
zend_hash_apply_with_arguments(Z_ARRVAL_P(entry) TSRMLS_CC, (apply_func_args_t) add_config_entry_cb, 1, tmp);
|
||||
add_assoc_zval_ex(retval, hash_key->key->val, hash_key->key->len, &tmp);
|
||||
zend_hash_update(Z_ARRVAL_P(retval), hash_key->key, &tmp);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -5926,8 +5926,7 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int cal
|
||||
ZVAL_DUP(&element, arg2);
|
||||
|
||||
if (arg3 && Z_STRLEN_P(arg3) > 0) {
|
||||
//???
|
||||
add_assoc_zval_ex(find_hash, Z_STRVAL_P(arg3), Z_STRLEN_P(arg3), &element);
|
||||
zend_symtable_update(Z_ARRVAL_P(find_hash), Z_STR_P(arg3), &element);
|
||||
} else {
|
||||
add_next_index_zval(find_hash, &element);
|
||||
}
|
||||
|
@ -659,7 +659,7 @@ finish:
|
||||
if (header_init) {
|
||||
zval ztmp;
|
||||
array_init(&ztmp);
|
||||
zend_set_local_var("http_response_header", sizeof("http_response_header")-1, &ztmp, 0 TSRMLS_CC);
|
||||
zend_set_local_var_str("http_response_header", sizeof("http_response_header")-1, &ztmp, 0 TSRMLS_CC);
|
||||
}
|
||||
|
||||
response_header = zend_hash_str_find(&EG(active_symbol_table)->ht, "http_response_header", sizeof("http_response_header")-1);
|
||||
|
@ -556,8 +556,7 @@ PHP_FUNCTION(stream_get_transports)
|
||||
zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos);
|
||||
while (zend_hash_get_current_key_ex(stream_xport_hash,
|
||||
&stream_xport, &num_key, 0, &pos) == HASH_KEY_IS_STRING) {
|
||||
//???
|
||||
add_next_index_stringl(return_value, stream_xport->val, stream_xport->len, 1);
|
||||
add_next_index_str(return_value, STR_COPY(stream_xport));
|
||||
zend_hash_move_forward_ex(stream_xport_hash, &pos);
|
||||
}
|
||||
} else {
|
||||
@ -586,8 +585,7 @@ PHP_FUNCTION(stream_get_wrappers)
|
||||
(key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTENT;
|
||||
zend_hash_move_forward_ex(url_stream_wrappers_hash, &pos)) {
|
||||
if (key_flags == HASH_KEY_IS_STRING) {
|
||||
//???
|
||||
add_next_index_stringl(return_value, stream_protocol->val, stream_protocol->len, 1);
|
||||
add_next_index_str(return_value, STR_COPY(stream_protocol));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -3948,8 +3948,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit
|
||||
switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(subject), &string_key,
|
||||
&num_key, 0, NULL)) {
|
||||
case HASH_KEY_IS_STRING:
|
||||
//???
|
||||
add_assoc_zval_ex(return_value, string_key->val, string_key->len, &result);
|
||||
zend_hash_update(Z_ARRVAL_P(return_value), string_key, &result);
|
||||
break;
|
||||
|
||||
case HASH_KEY_IS_LONG:
|
||||
|
@ -859,7 +859,7 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c
|
||||
(Z_TYPE(EG(user_error_handler)) == IS_UNDEF || !(EG(user_error_handler_error_reporting) & type))) {
|
||||
zval tmp;
|
||||
ZVAL_STRINGL(&tmp, buffer, buffer_len);
|
||||
if (zend_set_local_var("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0 TSRMLS_CC) == FAILURE) {
|
||||
if (zend_set_local_var_str("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0 TSRMLS_CC) == FAILURE) {
|
||||
zval_ptr_dtor(&tmp);
|
||||
}
|
||||
}
|
||||
@ -1192,7 +1192,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
|
||||
if (EG(active_symbol_table)) {
|
||||
zval tmp;
|
||||
ZVAL_STRINGL(&tmp, buffer, buffer_len);
|
||||
if (zend_set_local_var("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0 TSRMLS_CC) == FAILURE) {
|
||||
if (zend_set_local_var_str("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0 TSRMLS_CC) == FAILURE) {
|
||||
zval_ptr_dtor(&tmp);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user