]> granicus.if.org Git - php/commitdiff
optimize the lookups by avoiding a copy and then another pass
authorSterling Hughes <sterling@php.net>
Tue, 20 May 2003 18:28:14 +0000 (18:28 +0000)
committerSterling Hughes <sterling@php.net>
Tue, 20 May 2003 18:28:14 +0000 (18:28 +0000)
Naked Dancing Girls should be given to: Myself, Zeev, Marcus,
and George Schlossnagle (in no particular order)

Zend/zend_execute_API.c
Zend/zend_operators.c
Zend/zend_operators.h

index 34b576860f659c00fbe919bed764e3ef31942267..3d04fe7747c2b10f195cd000a649c050192ff575 100644 (file)
@@ -540,9 +540,9 @@ int fast_call_user_function(HashTable *function_table, zval **object_pp, zval *f
        zval *orig_free_op1, *orig_free_op2;
        int (*orig_unary_op)(zval *result, zval *op1);
        int (*orig_binary_op)(zval *result, zval *op1, zval *op2 TSRMLS_DC);
-       zval function_name_copy;
        zend_class_entry *current_scope;
        zend_class_entry *calling_scope = NULL;
+       char *function_name_lc;
        zval *current_this;
        zend_namespace *current_namespace = EG(active_namespace);
        zend_execute_data execute_data;
@@ -595,8 +595,7 @@ int fast_call_user_function(HashTable *function_table, zval **object_pp, zval *f
                                char *lc_class;
                                int found;
 
-                               lc_class = estrndup(Z_STRVAL_PP(object_pp), Z_STRLEN_PP(object_pp));
-                               zend_str_tolower(lc_class, Z_STRLEN_PP(object_pp));
+                               lc_class = zend_str_tolower_copy(Z_STRVAL_PP(object_pp), Z_STRLEN_PP(object_pp));
                                found = zend_lookup_class(lc_class, Z_STRLEN_PP(object_pp), &ce TSRMLS_CC);
                                efree(lc_class);
                                if (found == FAILURE)
@@ -613,16 +612,14 @@ int fast_call_user_function(HashTable *function_table, zval **object_pp, zval *f
                        return FAILURE;
                }
 
-               function_name_copy = *function_name;
-               zval_copy_ctor(&function_name_copy);
-               zend_str_tolower(function_name_copy.value.str.val, function_name_copy.value.str.len);
+               function_name_lc = zend_str_tolower_copy(function_name->value.str.val, function_name->value.str.len);
 
                original_function_state_ptr = EG(function_state_ptr);
-               if (zend_hash_find(function_table, function_name_copy.value.str.val, function_name_copy.value.str.len+1, (void **) &EX(function_state).function)==FAILURE) {
-                       zval_dtor(&function_name_copy);
+               if (zend_hash_find(function_table, function_name_lc, function_name->value.str.len+1, (void **) &EX(function_state).function)==FAILURE) {
+                       efree(function_name_lc);
                        return FAILURE;
                }
-               zval_dtor(&function_name_copy);
+               efree(function_name_lc);
                *function_pointer = EX(function_state).function;
        } else {
                EX(function_state).function = *function_pointer;
index 5a216afc930721220740e408a2a2bae010a1e200..f1caf779bbbe0d0fa3bad6db397c3d39e8c8dd98 100644 (file)
@@ -1579,6 +1579,24 @@ ZEND_API int zval_is_true(zval *op)
        return (op->value.lval ? 1 : 0);
 }
 
+ZEND_API char *zend_str_tolower_copy(char *str, unsigned int length)
+{
+       register char *result;
+       register char *start;
+       register char *p = str;
+       register char *end = p + length;
+
+       result = emalloc(length+1);
+       start = result;
+
+       while (p < end) {
+               *result++ = tolower(*p++);
+       }
+       *result = *end;
+       
+       return start;
+}
+       
 ZEND_API void zend_str_tolower(char *str, unsigned int length)
 {
        register char *p=str, *end=p+length;
index 2819323e11fbd5ba3a3a4acf0976cd05bbf1c9f4..368426e952b2f175f5071ce4073c70fba82beed0 100644 (file)
@@ -197,6 +197,7 @@ ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_
 ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
 ZEND_API void zend_str_tolower(char *str, unsigned int length);
+ZEND_API char *zend_str_tolower_copy(char *str, unsigned int length);
 ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2);
 ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
 ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2);