Improved empty string handling. Now ZE uses an interned string instead of allocation new empty string each time. (Some extensions might need to be fixed using str_efree() instead of efree() to support interned strings).

This commit is contained in:
Dmitry Stogov 2013-12-26 14:47:13 +04:00
parent 0ff0e82f26
commit 03a37de9b3
11 changed files with 22 additions and 8 deletions

2
NEWS
View File

@ -7,6 +7,8 @@ PHP NEWS
- Core:
. Improved IS_VAR operands fetching. (Laruence, Dmitry)
. Improved empty string handling. Now ZE uses an interned string instead of
allocation new empty string each time. (Laruence, Dmitry)
. Implemented internal operator overloading
(RFC: https://wiki.php.net/rfc/operator_overloading_gmp). (Nikita)
. Made calls from incompatible context issue an E_DEPRECATED warning instead

View File

@ -680,7 +680,11 @@ END_EXTERN_C()
#define STR_FREE(ptr) if (ptr) { str_efree(ptr); }
#define STR_FREE_REL(ptr) if (ptr) { str_efree_rel(ptr); }
#ifndef ZTS
#define STR_EMPTY_ALLOC() CG(interned_empty_string)? CG(interned_empty_string) : estrndup("", sizeof("")-1)
#else
#define STR_EMPTY_ALLOC() estrndup("", sizeof("")-1)
#endif
#define STR_REALLOC(ptr, size) \
ptr = (char *) erealloc(ptr, size);

View File

@ -2461,14 +2461,14 @@ void zend_do_build_full_name(znode *result, znode *prefix, znode *name, int is_c
if (is_class_member) {
length = sizeof("::")-1 + Z_STRLEN(result->u.constant) + Z_STRLEN(name->u.constant);
Z_STRVAL(result->u.constant) = erealloc(Z_STRVAL(result->u.constant), length+1);
Z_STRVAL(result->u.constant) = str_erealloc(Z_STRVAL(result->u.constant), length+1);
memcpy(&Z_STRVAL(result->u.constant)[Z_STRLEN(result->u.constant)], "::", sizeof("::")-1);
memcpy(&Z_STRVAL(result->u.constant)[Z_STRLEN(result->u.constant) + sizeof("::")-1], Z_STRVAL(name->u.constant), Z_STRLEN(name->u.constant)+1);
str_efree(Z_STRVAL(name->u.constant));
Z_STRLEN(result->u.constant) = length;
} else {
length = sizeof("\\")-1 + Z_STRLEN(result->u.constant) + Z_STRLEN(name->u.constant);
Z_STRVAL(result->u.constant) = erealloc(Z_STRVAL(result->u.constant), length+1);
Z_STRVAL(result->u.constant) = str_erealloc(Z_STRVAL(result->u.constant), length+1);
memcpy(&Z_STRVAL(result->u.constant)[Z_STRLEN(result->u.constant)], "\\", sizeof("\\")-1);
memcpy(&Z_STRVAL(result->u.constant)[Z_STRLEN(result->u.constant) + sizeof("\\")-1], Z_STRVAL(name->u.constant), Z_STRLEN(name->u.constant)+1);
str_efree(Z_STRVAL(name->u.constant));

View File

@ -28,7 +28,7 @@
/* The first number is the engine version and the rest is the date.
* This way engine 2/3 API no. is always greater than engine 1 API no..
*/
#define ZEND_EXTENSION_API_NO 220131107
#define ZEND_EXTENSION_API_NO 220131226
typedef struct _zend_extension_version_info {
int zend_extension_api_no;

View File

@ -146,6 +146,9 @@ struct _zend_compiler_globals {
char *interned_strings_end;
char *interned_strings_top;
char *interned_strings_snapshot_top;
#ifndef ZTS
char *interned_empty_string;
#endif
HashTable interned_strings;

View File

@ -33,7 +33,7 @@
#define ZEND_MODULE_INFO_FUNC_ARGS zend_module_entry *zend_module TSRMLS_DC
#define ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU zend_module TSRMLS_CC
#define ZEND_MODULE_API_NO 20131106
#define ZEND_MODULE_API_NO 20131226
#ifdef ZTS
#define USING_ZTS 1
#else

View File

@ -61,6 +61,8 @@ void zend_interned_strings_init(TSRMLS_D)
mprotect(CG(interned_strings_start), CG(interned_strings_end) - CG(interned_strings_start), PROT_READ);
#endif
/* interned empty string */
CG(interned_empty_string) = zend_new_interned_string_int("", sizeof(""), 0 TSRMLS_CC);
#endif
zend_new_interned_string = zend_new_interned_string_int;

View File

@ -387,6 +387,9 @@ static void accel_use_shm_interned_strings(TSRMLS_D)
{
Bucket *p, *q;
/* empty string */
CG(interned_empty_string) = accel_new_interned_string("", sizeof(""), 0 TSRMLS_CC);
/* function table hash keys */
p = CG(function_table)->pListHead;
while (p) {

View File

@ -86,7 +86,7 @@ PHP_METHOD(SessionHandler, read)
}
RETVAL_STRINGL(val, val_len, 1);
efree(val);
str_efree(val);
return;
}
/* }}} */

View File

@ -513,9 +513,9 @@ static void php_session_initialize(TSRMLS_D) /* {{{ */
PHP_MD5Final(PS(session_data_hash), &context);
php_session_decode(val, vallen TSRMLS_CC);
efree(val);
str_efree(val);
} else {
memset(PS(session_data_hash),'\0', 16);
memset(PS(session_data_hash),'\0', 16);
}
if (!PS(use_cookies) && PS(send_cookie)) {

View File

@ -2059,7 +2059,7 @@ SPL_METHOD(RegexIterator, accept)
}
if (use_copy) {
efree(subject);
str_efree(subject);
}
} /* }}} */