Micro optimization

This commit is contained in:
Xinchen Hui 2014-12-21 23:16:25 -05:00
parent 201e1b8a8d
commit c24125e2f9
5 changed files with 16 additions and 31 deletions

View file

@ -1286,8 +1286,6 @@ ZEND_API union _zend_function *zend_std_get_constructor(zend_object *zobj) /* {{
} }
/* }}} */ /* }}} */
int zend_compare_symbol_tables_i(HashTable *ht1, HashTable *ht2);
static int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */ static int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
{ {
zend_object *zobj1, *zobj2; zend_object *zobj1, *zobj2;
@ -1343,7 +1341,7 @@ static int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
if (!zobj2->properties) { if (!zobj2->properties) {
rebuild_object_properties(zobj2); rebuild_object_properties(zobj2);
} }
return zend_compare_symbol_tables_i(zobj1->properties, zobj2->properties); return zend_compare_symbol_tables(zobj1->properties, zobj2->properties);
} }
} }
/* }}} */ /* }}} */

View file

@ -1791,7 +1791,7 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
return SUCCESS; return SUCCESS;
case TYPE_PAIR(IS_ARRAY, IS_ARRAY): case TYPE_PAIR(IS_ARRAY, IS_ARRAY):
zend_compare_arrays(result, op1, op2); ZVAL_LONG(result, zend_compare_arrays(op1, op2));
return SUCCESS; return SUCCESS;
case TYPE_PAIR(IS_NULL, IS_NULL): case TYPE_PAIR(IS_NULL, IS_NULL):
@ -2601,35 +2601,28 @@ static int hash_zval_compare_function(zval *z1, zval *z2) /* {{{ */
} }
/* }}} */ /* }}} */
ZEND_API int zend_compare_symbol_tables_i(HashTable *ht1, HashTable *ht2) /* {{{ */ ZEND_API int zend_compare_symbol_tables(HashTable *ht1, HashTable *ht2) /* {{{ */
{ {
return ht1 == ht2 ? 0 : zend_hash_compare(ht1, ht2, (compare_func_t) hash_zval_compare_function, 0); return ht1 == ht2 ? 0 : zend_hash_compare(ht1, ht2, (compare_func_t) hash_zval_compare_function, 0);
} }
/* }}} */ /* }}} */
ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2) /* {{{ */ ZEND_API int zend_compare_arrays(zval *a1, zval *a2) /* {{{ */
{ {
ZVAL_LONG(result, ht1 == ht2 ? 0 : zend_hash_compare(ht1, ht2, (compare_func_t) hash_zval_compare_function, 0)); return zend_compare_symbol_tables(Z_ARRVAL_P(a1), Z_ARRVAL_P(a2));
} }
/* }}} */ /* }}} */
ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2) /* {{{ */ ZEND_API int zend_compare_objects(zval *o1, zval *o2) /* {{{ */
{
zend_compare_symbol_tables(result, Z_ARRVAL_P(a1), Z_ARRVAL_P(a2));
}
/* }}} */
ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2) /* {{{ */
{ {
if (Z_OBJ_P(o1) == Z_OBJ_P(o2)) { if (Z_OBJ_P(o1) == Z_OBJ_P(o2)) {
ZVAL_LONG(result, 0); return 0;
return;
} }
if (Z_OBJ_HT_P(o1)->compare_objects == NULL) { if (Z_OBJ_HT_P(o1)->compare_objects == NULL) {
ZVAL_LONG(result, 1); return 1;
} else { } else {
ZVAL_LONG(result, Z_OBJ_HT_P(o1)->compare_objects(o1, o2)); return Z_OBJ_HT_P(o1)->compare_objects(o1, o2);
} }
} }
/* }}} */ /* }}} */

View file

@ -338,9 +338,9 @@ ZEND_API int zend_binary_strcasecmp_l(const char *s1, size_t len1, const char *s
ZEND_API int zend_binary_strncasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2, size_t length); ZEND_API int zend_binary_strncasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2, size_t length);
ZEND_API zend_long zendi_smart_strcmp(zval *s1, zval *s2); ZEND_API zend_long zendi_smart_strcmp(zval *s1, zval *s2);
ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2); ZEND_API int zend_compare_symbol_tables(HashTable *ht1, HashTable *ht2);
ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2); ZEND_API int zend_compare_arrays(zval *a1, zval *a2);
ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2); ZEND_API int zend_compare_objects(zval *o1, zval *o2);
ZEND_API int zend_atoi(const char *str, int str_len); ZEND_API int zend_atoi(const char *str, int str_len);
ZEND_API zend_long zend_atol(const char *str, int str_len); ZEND_API zend_long zend_atol(const char *str, int str_len);

View file

@ -949,15 +949,13 @@ static int spl_array_compare_objects(zval *o1, zval *o2) /* {{{ */
spl_array_object *intern1, spl_array_object *intern1,
*intern2; *intern2;
int result = 0; int result = 0;
zval temp_zv;
intern1 = Z_SPLARRAY_P(o1); intern1 = Z_SPLARRAY_P(o1);
intern2 = Z_SPLARRAY_P(o2); intern2 = Z_SPLARRAY_P(o2);
ht1 = spl_array_get_hash_table(intern1, 0); ht1 = spl_array_get_hash_table(intern1, 0);
ht2 = spl_array_get_hash_table(intern2, 0); ht2 = spl_array_get_hash_table(intern2, 0);
zend_compare_symbol_tables(&temp_zv, ht1, ht2); result = zend_compare_symbol_tables(ht1, ht2);
result = (int)Z_LVAL(temp_zv);
/* if we just compared std.properties, don't do it again */ /* if we just compared std.properties, don't do it again */
if (result == 0 && if (result == 0 &&
!(ht1 == intern1->std.properties && ht2 == intern2->std.properties)) { !(ht1 == intern1->std.properties && ht2 == intern2->std.properties)) {

View file

@ -4937,15 +4937,11 @@ static int user_tick_function_compare(user_tick_function_entry * tick_fe1, user_
int ret; int ret;
if (Z_TYPE_P(func1) == IS_STRING && Z_TYPE_P(func2) == IS_STRING) { if (Z_TYPE_P(func1) == IS_STRING && Z_TYPE_P(func2) == IS_STRING) {
ret = (zend_binary_zval_strcmp(func1, func2) == 0); ret = zend_binary_zval_strcmp(func1, func2) == 0;
} else if (Z_TYPE_P(func1) == IS_ARRAY && Z_TYPE_P(func2) == IS_ARRAY) { } else if (Z_TYPE_P(func1) == IS_ARRAY && Z_TYPE_P(func2) == IS_ARRAY) {
zval result; ret = zend_compare_arrays(func1, func2) == 0;
zend_compare_arrays(&result, func1, func2);
ret = (Z_LVAL(result) == 0);
} else if (Z_TYPE_P(func1) == IS_OBJECT && Z_TYPE_P(func2) == IS_OBJECT) { } else if (Z_TYPE_P(func1) == IS_OBJECT && Z_TYPE_P(func2) == IS_OBJECT) {
zval result; ret = zend_compare_objects(func1, func2) == 0;
zend_compare_objects(&result, func1, func2);
ret = (Z_LVAL(result) == 0);
} else { } else {
ret = 0; ret = 0;
} }