summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2011-07-10 12:37:42 +0000
committerFelipe Pena <felipe@php.net>2011-07-10 12:37:42 +0000
commit9aa25d09383d11fe5e00aa72ecf88d7ee935b1a7 (patch)
treed64e6d69f75c188e71bd9897bdcfa60abcbcf09e
parentc6396dd9deb05c9aa116f9877f6496ae62e8b539 (diff)
downloadphp-git-9aa25d09383d11fe5e00aa72ecf88d7ee935b1a7.tar.gz
- Minor optimization taking the computed hash of interned strings
-rw-r--r--Zend/zend_API.c29
-rw-r--r--Zend/zend_compile.c20
-rw-r--r--Zend/zend_constants.c9
3 files changed, 41 insertions, 17 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index b3ea607361..cacfcfb9ff 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -1917,7 +1917,7 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
const zend_function_entry *ptr = functions;
zend_function function, *reg_function;
zend_internal_function *internal_function = (zend_internal_function *)&function;
- int count=0, unload=0;
+ int count=0, unload=0, result=0;
HashTable *target_function_table = function_table;
int error_type;
zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__unset = NULL, *__isset = NULL, *__call = NULL, *__callstatic = NULL, *__tostring = NULL;
@@ -2024,24 +2024,21 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
fname_len = strlen(ptr->fname);
lowercase_name = zend_new_interned_string(zend_str_tolower_dup(ptr->fname, fname_len), fname_len + 1, 1 TSRMLS_CC);
if (IS_INTERNED(lowercase_name)) {
- if (zend_hash_quick_add(target_function_table, lowercase_name, fname_len+1, INTERNED_HASH(lowercase_name), &function, sizeof(zend_function), (void**)&reg_function) == FAILURE) {
- unload=1;
- str_efree(lowercase_name);
- break;
- }
- } else {
- if (zend_hash_add(target_function_table, lowercase_name, fname_len+1, &function, sizeof(zend_function), (void**)&reg_function) == FAILURE) {
- unload=1;
- str_efree(lowercase_name);
- break;
- }
+ result = zend_hash_quick_add(target_function_table, lowercase_name, fname_len+1, INTERNED_HASH(lowercase_name), &function, sizeof(zend_function), (void**)&reg_function);
+ } else {
+ result = zend_hash_add(target_function_table, lowercase_name, fname_len+1, &function, sizeof(zend_function), (void**)&reg_function);
+ }
+ if (result == FAILURE) {
+ unload=1;
+ str_efree(lowercase_name);
+ break;
}
if (scope) {
/* Look for ctor, dtor, clone
* If it's an old-style constructor, store it only if we don't have
* a constructor already.
*/
- if ((fname_len == class_name_len) && !memcmp(lowercase_name, lc_class_name, class_name_len+1) && !ctor) {
+ if ((fname_len == class_name_len) && !ctor && !memcmp(lowercase_name, lc_class_name, class_name_len+1)) {
ctor = reg_function;
} else if ((fname_len == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME))) {
ctor = reg_function;
@@ -2395,7 +2392,11 @@ static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class
zend_str_tolower_copy(lowercase_name, orig_class_entry->name, class_entry->name_length);
lowercase_name = zend_new_interned_string(lowercase_name, class_entry->name_length + 1, 1 TSRMLS_CC);
- zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, &class_entry, sizeof(zend_class_entry *), NULL);
+ if (IS_INTERNED(lowercase_name)) {
+ zend_hash_quick_update(CG(class_table), lowercase_name, class_entry->name_length+1, INTERNED_HASH(lowercase_name), &class_entry, sizeof(zend_class_entry *), NULL);
+ } else {
+ zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, &class_entry, sizeof(zend_class_entry *), NULL);
+ }
str_efree(lowercase_name);
return class_entry;
}
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index bfa6421547..2075814496 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -1543,9 +1543,16 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
op_array.line_start = zend_get_compiled_lineno(TSRMLS_C);
if (is_method) {
+ int result;
+
lcname = zend_new_interned_string(zend_str_tolower_dup(name, name_len), name_len + 1, 1 TSRMLS_CC);
- if (zend_hash_add(&CG(active_class_entry)->function_table, lcname, name_len+1, &op_array, sizeof(zend_op_array), (void **) &CG(active_op_array)) == FAILURE) {
+ if (IS_INTERNED(lcname)) {
+ result = zend_hash_quick_add(&CG(active_class_entry)->function_table, lcname, name_len+1, INTERNED_HASH(lcname), &op_array, sizeof(zend_op_array), (void **) &CG(active_op_array));
+ } else {
+ result = zend_hash_add(&CG(active_class_entry)->function_table, lcname, name_len+1, &op_array, sizeof(zend_op_array), (void **) &CG(active_op_array));
+ }
+ if (result == FAILURE) {
zend_error(E_COMPILE_ERROR, "Cannot redeclare %s::%s()", CG(active_class_entry)->name, name);
}
@@ -4860,6 +4867,8 @@ void zend_do_declare_property(const znode *var_name, const znode *value, zend_ui
void zend_do_declare_class_constant(znode *var_name, const znode *value TSRMLS_DC) /* {{{ */
{
zval *property;
+ char *cname = NULL;
+ int result;
if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
zend_error(E_COMPILE_ERROR, "Arrays are not allowed in class constants");
@@ -4872,8 +4881,15 @@ void zend_do_declare_class_constant(znode *var_name, const znode *value TSRMLS_D
ALLOC_ZVAL(property);
*property = value->u.constant;
+
+ cname = zend_new_interned_string(var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, 0 TSRMLS_CC);
- if (zend_hash_add(&CG(active_class_entry)->constants_table, zend_new_interned_string(var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, 0 TSRMLS_CC), var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL)==FAILURE) {
+ if (IS_INTERNED(cname)) {
+ result = zend_hash_quick_add(&CG(active_class_entry)->constants_table, cname, var_name->u.constant.value.str.len+1, INTERNED_HASH(cname), &property, sizeof(zval *), NULL);
+ } else {
+ result = zend_hash_add(&CG(active_class_entry)->constants_table, cname, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL);
+ }
+ if (result == FAILURE) {
FREE_ZVAL(property);
zend_error(E_COMPILE_ERROR, "Cannot redefine class constant %s::%s", CG(active_class_entry)->name, var_name->u.constant.value.str.val);
}
diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c
index b695795720..58cc495ebb 100644
--- a/Zend/zend_constants.c
+++ b/Zend/zend_constants.c
@@ -452,6 +452,7 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
char *lowercase_name = NULL;
char *name;
int ret = SUCCESS;
+ ulong chash = 0;
#if 0
printf("Registering constant for module %d\n", c->module_number);
@@ -463,6 +464,7 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
zend_str_tolower(lowercase_name, c->name_len-1);
lowercase_name = zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC);
name = lowercase_name;
+ chash = IS_INTERNED(lowercase_name) ? INTERNED_HASH(lowercase_name) : 0;
} else {
char *slash = strrchr(c->name, '\\');
if(slash) {
@@ -470,15 +472,20 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
zend_str_tolower(lowercase_name, slash-c->name);
lowercase_name = zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC);
name = lowercase_name;
+
+ chash = IS_INTERNED(lowercase_name) ? INTERNED_HASH(lowercase_name) : 0;
} else {
name = c->name;
}
}
+ if (chash == 0) {
+ chash = zend_hash_func(name, c->name_len);
+ }
/* Check if the user is trying to define the internal pseudo constant name __COMPILER_HALT_OFFSET__ */
if ((c->name_len == sizeof("__COMPILER_HALT_OFFSET__")
&& !memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1))
- || zend_hash_add(EG(zend_constants), name, c->name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
+ || zend_hash_quick_add(EG(zend_constants), name, c->name_len, chash, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
/* The internal __COMPILER_HALT_OFFSET__ is prefixed by NULL byte */
if (c->name[0] == '\0' && c->name_len > sizeof("\0__COMPILER_HALT_OFFSET__")