com php-src: Comparison optimization: Zend/zend_operators.c
| From: | Dmitry Stogov | Date: | Mon, 09 Jun 2014 13:00:22 +0000 |
| Subject: | com php-src: Comparison optimization: Zend/zend_operators.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-78780@lists.php.net to get a copy of this message | ||
Commit: 2d29f2d8d94591f7dab71c972f2e7c5909bb17ba
Author: Dmitry Stogov <dmitry@zend.com> Mon, 9 Jun 2014 17:00:22 +0400
Parents: dbaef7c03836c671534b1ad1f85a5629b4e9b95f
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2d29f2d8d94591f7dab71c972f2e7c5909bb17ba
Log:
Comparison optimization
Changed paths:
M Zend/zend_operators.c
Diff:
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index caf5e78..b40d3b1 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -1621,13 +1621,45 @@ ZEND_API int string_compare_function_ex(zval *result, zval *op1, zval *op2,
zend
ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
- return string_compare_function_ex(result, op1, op2, 0 TSRMLS_CC);
+ if (EXPECTED(Z_TYPE_P(op1) == IS_STRING) &&
+ EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
+ if (Z_STR_P(op1) == Z_STR_P(op2)) {
+ ZVAL_LONG(result, 0);
+ } else {
+ ZVAL_LONG(result, zend_binary_strcmp(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2),
Z_STRLEN_P(op2)));
+ }
+ } else {
+ zend_string *str1 = zval_get_string(op1);
+ zend_string *str2 = zval_get_string(op2);
+
+ ZVAL_LONG(result, zend_binary_strcmp(str1->val, str1->len, str2->val, str2->len));
+
+ STR_RELEASE(str1);
+ STR_RELEASE(str2);
+ }
+ return SUCCESS;
}
/* }}} */
ZEND_API int string_case_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
- return string_compare_function_ex(result, op1, op2, 1 TSRMLS_CC);
+ if (EXPECTED(Z_TYPE_P(op1) == IS_STRING) &&
+ EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
+ if (Z_STR_P(op1) == Z_STR_P(op2)) {
+ ZVAL_LONG(result, 0);
+ } else {
+ ZVAL_LONG(result, zend_binary_strcasecmp_l(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2),
Z_STRLEN_P(op2)));
+ }
+ } else {
+ zend_string *str1 = zval_get_string(op1);
+ zend_string *str2 = zval_get_string(op2);
+
+ ZVAL_LONG(result, zend_binary_strcasecmp_l(str1->val, str1->len, str2->val,
str1->len));
+
+ STR_RELEASE(str1);
+ STR_RELEASE(str2);
+ }
+ return SUCCESS;
}
/* }}} */