Skip to content

Commit f643527

Browse files
author
felipe
committed
- Optimize property finding by zend_hash_quick_find
git-svn-id: http://svn.php.net/repository/php/php-src/trunk@312322 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent ead7096 commit f643527

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Zend/zend_compile.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -3851,12 +3851,12 @@ static void zend_do_traits_method_binding(zend_class_entry *ce TSRMLS_DC) /* {{{
38513851
free(resulting_table);
38523852
}
38533853

3854-
static zend_class_entry* find_first_definition(zend_class_entry *ce, size_t current_trait, char* prop_name, int prop_name_length, zend_class_entry *coliding_ce) /* {{{ */
3854+
static zend_class_entry* find_first_definition(zend_class_entry *ce, size_t current_trait, char* prop_name, int prop_name_length, ulong prop_hash, zend_class_entry *coliding_ce) /* {{{ */
38553855
{
38563856
size_t i;
38573857
zend_property_info *coliding_prop;
38583858
for (i = 0; (i < current_trait) && (i < ce->num_traits); i++) {
3859-
if (zend_hash_find(&ce->traits[i]->properties_info, prop_name, prop_name_length+1, (void **) &coliding_prop) == SUCCESS) {
3859+
if (zend_hash_quick_find(&ce->traits[i]->properties_info, prop_name, prop_name_length+1, prop_hash, (void **) &coliding_prop) == SUCCESS) {
38603860
return ce->traits[i];
38613861
}
38623862
}
@@ -3872,6 +3872,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {
38723872
zval compare_result;
38733873
char* prop_name;
38743874
int prop_name_length;
3875+
ulong prop_hash;
38753876
char* class_name_unused;
38763877
zend_bool prop_found;
38773878
zend_bool not_compatible;
@@ -3894,6 +3895,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {
38943895
/* first get the unmangeld name if necessary,
38953896
then check whether the property is already there */
38963897
if ((property_info->flags & ZEND_ACC_PPP_MASK) == ZEND_ACC_PUBLIC) {
3898+
prop_hash = property_info->h;
38973899
prop_name = property_info->name;
38983900
prop_name_length = property_info->name_length;
38993901
prop_found = zend_hash_quick_find(&ce->properties_info,
@@ -3904,14 +3906,15 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {
39043906
zend_unmangle_property_name(property_info->name, property_info->name_length,
39053907
&class_name_unused, &prop_name);
39063908
prop_name_length = strlen(prop_name);
3907-
prop_found = zend_hash_find(&ce->properties_info, prop_name, prop_name_length+1, (void **) &coliding_prop) == SUCCESS;
3909+
prop_hash = zend_get_hash_value(prop_name, prop_name_length + 1);
3910+
prop_found = zend_hash_quick_find(&ce->properties_info, prop_name, prop_name_length+1, prop_hash, (void **) &coliding_prop) == SUCCESS;
39083911
}
39093912

39103913
/* next: check for conflicts with current class */
39113914
if (prop_found) {
39123915
if (coliding_prop->flags & ZEND_ACC_SHADOW) {
39133916
/* this one is inherited, lets look it up in its own class */
3914-
zend_hash_find(&coliding_prop->ce->properties_info, prop_name, prop_name_length+1, (void **) &coliding_prop);
3917+
zend_hash_quick_find(&coliding_prop->ce->properties_info, prop_name, prop_name_length+1, prop_hash, (void **) &coliding_prop);
39153918
}
39163919
if ((coliding_prop->flags & ZEND_ACC_PPP_MASK) == (property_info->flags & ZEND_ACC_PPP_MASK)) {
39173920
/* flags are identical, now the value needs to be checked */
@@ -3921,8 +3924,8 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {
39213924
ce->traits[i]->default_static_members_table[property_info->offset] TSRMLS_CC) == FAILURE;
39223925
} else {
39233926
not_compatible = compare_function(&compare_result,
3924-
ce->default_properties_table[coliding_prop->offset],
3925-
ce->traits[i]->default_properties_table[property_info->offset] TSRMLS_CC) == FAILURE;
3927+
ce->default_properties_table[coliding_prop->offset],
3928+
ce->traits[i]->default_properties_table[property_info->offset] TSRMLS_CC) == FAILURE;
39263929
}
39273930
} else {
39283931
/* the flags are not identical, thus, we assume properties are not compatible */
@@ -3932,14 +3935,14 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {
39323935
if (not_compatible) {
39333936
zend_error(E_COMPILE_ERROR,
39343937
"%s and %s define the same property ($%s) in the composition of %s. However, the definition differs and is considered incompatible. Class was composed",
3935-
find_first_definition(ce, i, prop_name, prop_name_length, coliding_prop->ce)->name,
3938+
find_first_definition(ce, i, prop_name, prop_name_length, prop_hash, coliding_prop->ce)->name,
39363939
property_info->ce->name,
39373940
prop_name,
39383941
ce->name);
39393942
} else {
39403943
zend_error(E_STRICT,
39413944
"%s and %s define the same property ($%s) in the composition of %s. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed",
3942-
find_first_definition(ce, i, prop_name, prop_name_length, coliding_prop->ce)->name,
3945+
find_first_definition(ce, i, prop_name, prop_name_length, prop_hash, coliding_prop->ce)->name,
39433946
property_info->ce->name,
39443947
prop_name,
39453948
ce->name);

0 commit comments

Comments
 (0)