From 72c287bd232ef3a0dc5ae76a4b5b5879a8ee7786 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 21 Apr 2014 18:25:34 +0400 Subject: Combine HashTable.flags and HashTable.nApplyCount into single 32-bit word --- Zend/zend_operators.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Zend/zend_operators.c') diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 47e2562da8..0d45adf3af 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -683,7 +683,7 @@ static void convert_scalar_to_array(zval *op, int type TSRMLS_DC) /* {{{ */ switch (type) { case IS_ARRAY: ZVAL_NEW_ARR(op); - zend_hash_init(Z_ARRVAL_P(op), 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(Z_ARRVAL_P(op), 8, NULL, ZVAL_PTR_DTOR, 0); zend_hash_index_update(Z_ARRVAL_P(op), 0, &entry); break; case IS_OBJECT: @@ -707,7 +707,7 @@ ZEND_API void convert_to_array(zval *op) /* {{{ */ zval arr; ZVAL_NEW_ARR(&arr); - zend_hash_init(Z_ARRVAL(arr), 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(Z_ARRVAL(arr), 8, NULL, ZVAL_PTR_DTOR, 0); if (Z_OBJCE_P(op) == zend_ce_closure) { convert_scalar_to_array(op, IS_ARRAY TSRMLS_CC); if (Z_TYPE_P(op) == IS_ARRAY) { @@ -733,7 +733,7 @@ ZEND_API void convert_to_array(zval *op) /* {{{ */ break; case IS_NULL: ZVAL_NEW_ARR(op); - zend_hash_init(Z_ARRVAL_P(op), 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(Z_ARRVAL_P(op), 8, NULL, ZVAL_PTR_DTOR, 0); break; default: convert_scalar_to_array(op, IS_ARRAY TSRMLS_CC); -- cgit v1.2.1 From 5c8697184fa445fcd5fbd32b5334db2a0866464d Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 21 Apr 2014 17:10:35 +0200 Subject: Bring zval_get_string implement in line with make_printable_zval As make_printable_zval is the "main" string cast, match that one. --- Zend/zend_operators.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'Zend/zend_operators.c') diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 47e2562da8..93197a9b89 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -875,7 +875,7 @@ ZEND_API double zval_get_double(zval *op TSRMLS_DC) /* {{{ */ { zval tmp; ZVAL_DUP(&tmp, op); - convert_object_to_type(op, IS_DOUBLE, convert_to_double); + convert_object_to_type(&tmp, IS_DOUBLE, convert_to_double); if (Z_TYPE(tmp) == IS_DOUBLE) { return Z_DVAL(tmp); @@ -901,7 +901,7 @@ ZEND_API zend_string *zval_get_string(zval *op TSRMLS_DC) /* {{{ */ case IS_STRING: return STR_COPY(Z_STR_P(op)); case IS_BOOL: - if (Z_LVAL_P(op)) { + if (Z_BVAL_P(op)) { return STR_INIT("1", 1, 0); } else { return STR_EMPTY_ALLOC(); @@ -932,17 +932,27 @@ ZEND_API zend_string *zval_get_string(zval *op TSRMLS_DC) /* {{{ */ return STR_INIT("Array", sizeof("Array")-1, 0); case IS_OBJECT: { zval tmp; - ZVAL_DUP(&tmp, op); - convert_object_to_type(op, IS_STRING, convert_to_string); - - if (Z_TYPE(tmp) == IS_STRING) { - return Z_STR(tmp); - } else { - zend_error(E_NOTICE, "Object of class %s to string conversion", Z_OBJCE_P(op)->name->val); - zval_dtor(&tmp); - return STR_INIT("Object", sizeof("Object")-1, 0); + //???if (zend_std_cast_object_tostring(op, &tmp, IS_STRING TSRMLS_CC) == SUCCESS) { + //??? return Z_STR(tmp); + //???} + if (Z_OBJ_HT_P(op)->cast_object) { + if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, IS_STRING TSRMLS_CC) == SUCCESS) { + return Z_STR(tmp); + } + } else if (Z_OBJ_HT_P(op)->get) { + zval *z = Z_OBJ_HT_P(op)->get(op, &tmp TSRMLS_CC); + if (Z_TYPE_P(z) != IS_OBJECT) { + zend_string *str = zval_get_string(z TSRMLS_CC); + zval_ptr_dtor(z); + return str; + } + zval_ptr_dtor(z); } + zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(op)->name->val); + return STR_EMPTY_ALLOC(); } + case IS_REFERENCE: + return zval_get_string(Z_REFVAL_P(op)); default: //??? original code returns bool(0) return STR_EMPTY_ALLOC(); -- cgit v1.2.1 From 0d43a277b8dec6ea9f804eeb1a68c05047a22c4f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 21 Apr 2014 17:51:15 +0200 Subject: Use zval_get_string in a few more places --- Zend/zend_operators.c | 58 ++++++++++----------------------------------------- 1 file changed, 11 insertions(+), 47 deletions(-) (limited to 'Zend/zend_operators.c') diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 93197a9b89..f593e97ada 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -1557,35 +1557,17 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{ ZEND_API int string_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive TSRMLS_DC) /* {{{ */ { - zval op1_copy, op2_copy; - int use_copy1 = 0, use_copy2 = 0; - - if (Z_TYPE_P(op1) != IS_STRING) { - zend_make_printable_zval(op1, &op1_copy, &use_copy1); - } - if (Z_TYPE_P(op2) != IS_STRING) { - zend_make_printable_zval(op2, &op2_copy, &use_copy2); - } - - if (use_copy1) { - op1 = &op1_copy; - } - if (use_copy2) { - op2 = &op2_copy; - } + zend_string *str1 = zval_get_string(op1 TSRMLS_CC), + *str2 = zval_get_string(op2 TSRMLS_CC); if (case_insensitive) { - ZVAL_LONG(result, zend_binary_zval_strcasecmp(op1, op2)); + ZVAL_LONG(result, zend_binary_strcasecmp_l(str1->val, str1->len, str2->val, str1->len)); } else { - ZVAL_LONG(result, zend_binary_zval_strcmp(op1, op2)); + ZVAL_LONG(result, zend_binary_strcmp(str1->val, str1->len, str2->val, str2->len)); } - if (use_copy1) { - zval_dtor(op1); - } - if (use_copy2) { - zval_dtor(op2); - } + STR_RELEASE(str1); + STR_RELEASE(str2); return SUCCESS; } /* }}} */ @@ -1605,31 +1587,13 @@ ZEND_API int string_case_compare_function(zval *result, zval *op1, zval *op2 TSR #if HAVE_STRCOLL ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */ { - zval op1_copy, op2_copy; - int use_copy1 = 0, use_copy2 = 0; - - if (Z_TYPE_P(op1) != IS_STRING) { - zend_make_printable_zval(op1, &op1_copy, &use_copy1); - } - if (Z_TYPE_P(op2) != IS_STRING) { - zend_make_printable_zval(op2, &op2_copy, &use_copy2); - } - - if (use_copy1) { - op1 = &op1_copy; - } - if (use_copy2) { - op2 = &op2_copy; - } + zend_string *str1 = zval_get_string(op1 TSRMLS_CC), + *str2 = zval_get_string(op2 TSRMLS_CC); - ZVAL_LONG(result, strcoll(Z_STRVAL_P(op1), Z_STRVAL_P(op2))); + ZVAL_LONG(result, strcoll(str1->val, str2->val)); - if (use_copy1) { - zval_dtor(op1); - } - if (use_copy2) { - zval_dtor(op2); - } + STR_RELEASE(str1); + STR_RELEASE(str2); return SUCCESS; } /* }}} */ -- cgit v1.2.1 From 4ed452c1b5b81f99212594ec7f57475a16372d45 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 21 Apr 2014 22:36:01 +0400 Subject: Convert zval_get_string() into "fast path" macro and "slow path" function --- Zend/zend_operators.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'Zend/zend_operators.c') diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 3b596bb6c0..0824d8d98f 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -893,8 +893,9 @@ ZEND_API double zval_get_double(zval *op TSRMLS_DC) /* {{{ */ } /* }}} */ -ZEND_API zend_string *zval_get_string(zval *op TSRMLS_DC) /* {{{ */ +ZEND_API zend_string *_zval_get_string_func(zval *op TSRMLS_DC) /* {{{ */ { +try_again: switch (Z_TYPE_P(op)) { case IS_NULL: return STR_EMPTY_ALLOC(); @@ -907,18 +908,18 @@ ZEND_API zend_string *zval_get_string(zval *op TSRMLS_DC) /* {{{ */ return STR_EMPTY_ALLOC(); } case IS_RESOURCE: { - char *str; - int len = zend_spprintf(&str, 0, "Resource id #%ld", Z_RES_HANDLE_P(op)); - zend_string *retval = STR_INIT(str, len, 0); - efree(str); - return retval; + char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG]; + int len; + + len = snprintf(buf, sizeof(buf), "Resource id #%ld", Z_RES_HANDLE_P(op)); + return STR_INIT(buf, len, 0); } case IS_LONG: { - char *str; - int len = zend_spprintf(&str, 0, "%ld", Z_LVAL_P(op)); - zend_string *retval = STR_INIT(str, len, 0); - efree(str); - return retval; + char buf[MAX_LENGTH_OF_LONG + 1]; + int len; + + len = snprintf(buf, sizeof(buf), "%ld", Z_LVAL_P(op)); + return STR_INIT(buf, len, 0); } case IS_DOUBLE: { char *str; @@ -942,7 +943,7 @@ ZEND_API zend_string *zval_get_string(zval *op TSRMLS_DC) /* {{{ */ } else if (Z_OBJ_HT_P(op)->get) { zval *z = Z_OBJ_HT_P(op)->get(op, &tmp TSRMLS_CC); if (Z_TYPE_P(z) != IS_OBJECT) { - zend_string *str = zval_get_string(z TSRMLS_CC); + zend_string *str = zval_get_string(z); zval_ptr_dtor(z); return str; } @@ -952,7 +953,8 @@ ZEND_API zend_string *zval_get_string(zval *op TSRMLS_DC) /* {{{ */ return STR_EMPTY_ALLOC(); } case IS_REFERENCE: - return zval_get_string(Z_REFVAL_P(op)); + op = Z_REFVAL_P(op); + goto try_again; default: //??? original code returns bool(0) return STR_EMPTY_ALLOC(); @@ -1557,8 +1559,8 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{ ZEND_API int string_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive TSRMLS_DC) /* {{{ */ { - zend_string *str1 = zval_get_string(op1 TSRMLS_CC), - *str2 = zval_get_string(op2 TSRMLS_CC); + zend_string *str1 = zval_get_string(op1); + zend_string *str2 = zval_get_string(op2); if (case_insensitive) { ZVAL_LONG(result, zend_binary_strcasecmp_l(str1->val, str1->len, str2->val, str1->len)); @@ -1587,8 +1589,8 @@ ZEND_API int string_case_compare_function(zval *result, zval *op1, zval *op2 TSR #if HAVE_STRCOLL ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */ { - zend_string *str1 = zval_get_string(op1 TSRMLS_CC), - *str2 = zval_get_string(op2 TSRMLS_CC); + zend_string *str1 = zval_get_string(op1); + zend_string *str2 = zval_get_string(op2); ZVAL_LONG(result, strcoll(str1->val, str2->val)); -- cgit v1.2.1 From fa588a5c82c0264dc10862495c993a914a421667 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 22 Apr 2014 02:34:34 +0400 Subject: Use shorter call chain --- Zend/zend_operators.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_operators.c') diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 0824d8d98f..d943ae739a 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -2400,7 +2400,7 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2) /* {{{ */ } } else { string_cmp: - Z_LVAL_P(result) = zend_binary_zval_strcmp(s1, s2); + Z_LVAL_P(result) = zend_binary_strcmp(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2)); ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_LVAL_P(result))); } } -- cgit v1.2.1