]> granicus.if.org Git - php/commitdiff
Comparison optimization
authorDmitry Stogov <dmitry@zend.com>
Mon, 9 Jun 2014 13:00:22 +0000 (17:00 +0400)
committerDmitry Stogov <dmitry@zend.com>
Mon, 9 Jun 2014 13:00:22 +0000 (17:00 +0400)
Zend/zend_operators.c

index caf5e78a42dd68a02d58466837d9bb36bcf09571..b40d3b14d69cdbb4c92f1fa8f0f4e9ecbd6a356f 100644 (file)
@@ -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;
 }
 /* }}} */