Skip to content
Browse files

Use interned strings for class names

  • Loading branch information...
1 parent 3d2a692 commit 3cf5ab9e567e302125f242aaff2f1bd41e3d5409 Dmitry Stogov committed Aug 5, 2010
Showing with 12 additions and 7 deletions.
  1. +4 −1 Zend/zend_API.h
  2. +2 −2 Zend/zend_compile.c
  3. +0 −2 Zend/zend_iterators.c
  4. +6 −2 Zend/zend_opcode.c
View
5 Zend/zend_API.h
@@ -167,7 +167,10 @@ typedef struct _zend_fcall_info_cache {
#define INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
{ \
int _len = class_name_len; \
- class_container.name = zend_strndup(class_name, _len); \
+ class_container.name = zend_new_interned_string(class_name, _len+1, 0); \
+ if (class_container.name == class_name) { \
+ class_container.name = zend_strndup(class_name, _len); \
+ } \
class_container.name_length = _len; \
class_container.builtin_functions = functions; \
class_container.constructor = NULL; \
View
4 Zend/zend_compile.c
@@ -4486,8 +4486,8 @@ void zend_do_begin_class_declaration(const znode *class_token, znode *class_name
new_class_entry = emalloc(sizeof(zend_class_entry));
new_class_entry->type = ZEND_USER_CLASS;
- new_class_entry->name = class_name->u.constant.value.str.val;
- new_class_entry->name_length = class_name->u.constant.value.str.len;
+ new_class_entry->name = zend_new_interned_string(Z_STRVAL(class_name->u.constant), Z_STRLEN(class_name->u.constant) + 1, 1 TSRMLS_CC);
+ new_class_entry->name_length = Z_STRLEN(class_name->u.constant);
zend_initialize_class_data(new_class_entry, 1 TSRMLS_CC);
new_class_entry->filename = zend_get_compiled_filename(TSRMLS_C);
View
2 Zend/zend_iterators.c
@@ -51,8 +51,6 @@ static zend_object_handlers iterator_object_handlers = {
ZEND_API void zend_register_iterator_wrapper(TSRMLS_D)
{
INIT_CLASS_ENTRY(zend_iterator_class_entry, "__iterator_wrapper", NULL);
- free(zend_iterator_class_entry.name);
- zend_iterator_class_entry.name = "__iterator_wrapper";
}
static void iter_wrapper_dtor(void *object, zend_object_handle handle TSRMLS_DC)
View
8 Zend/zend_opcode.c
@@ -301,7 +301,9 @@ ZEND_API void destroy_zend_class(zend_class_entry **pce)
efree(ce->default_static_members_table);
}
zend_hash_destroy(&ce->properties_info);
- efree(ce->name);
+ if (!IS_INTERNED(ce->name)) {
+ efree(ce->name);
+ }
zend_hash_destroy(&ce->function_table);
zend_hash_destroy(&ce->constants_table);
if (ce->num_interfaces > 0 && ce->interfaces) {
@@ -335,7 +337,9 @@ ZEND_API void destroy_zend_class(zend_class_entry **pce)
free(ce->default_static_members_table);
}
zend_hash_destroy(&ce->properties_info);
- free(ce->name);
+ if (!IS_INTERNED(ce->name)) {
+ free(ce->name);
+ }
zend_hash_destroy(&ce->function_table);
zend_hash_destroy(&ce->constants_table);
if (ce->num_interfaces > 0) {

0 comments on commit 3cf5ab9

Please sign in to comment.
Something went wrong with that request. Please try again.