Skip to content

Commit c174e4c

Browse files
committed
Change array sorting implementation to avoid two level callbacks system.
Simplify zval comparion API.
1 parent 2ea18cd commit c174e4c

File tree

8 files changed

+654
-270
lines changed

8 files changed

+654
-270
lines changed

Zend/zend_operators.c

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,92 +1662,88 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /
16621662
}
16631663
/* }}} */
16641664

1665-
ZEND_API int string_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive) /* {{{ */
1665+
ZEND_API int ZEND_FASTCALL string_compare_function_ex(zval *op1, zval *op2, zend_bool case_insensitive) /* {{{ */
16661666
{
16671667
zend_string *str1 = zval_get_string(op1);
16681668
zend_string *str2 = zval_get_string(op2);
1669+
int ret;
16691670

16701671
if (case_insensitive) {
1671-
ZVAL_LONG(result, zend_binary_strcasecmp_l(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str1)));
1672+
ret = zend_binary_strcasecmp_l(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str1));
16721673
} else {
1673-
ZVAL_LONG(result, zend_binary_strcmp(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str2)));
1674+
ret = zend_binary_strcmp(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str2));
16741675
}
16751676

16761677
zend_string_release(str1);
16771678
zend_string_release(str2);
1678-
return SUCCESS;
1679+
return ret;
16791680
}
16801681
/* }}} */
16811682

1682-
ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
1683+
ZEND_API int ZEND_FASTCALL string_compare_function(zval *op1, zval *op2) /* {{{ */
16831684
{
16841685
if (EXPECTED(Z_TYPE_P(op1) == IS_STRING) &&
16851686
EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
16861687
if (Z_STR_P(op1) == Z_STR_P(op2)) {
1687-
ZVAL_LONG(result, 0);
1688+
return 0;
16881689
} else {
1689-
ZVAL_LONG(result, zend_binary_strcmp(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2)));
1690+
return zend_binary_strcmp(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
16901691
}
16911692
} else {
16921693
zend_string *str1 = zval_get_string(op1);
16931694
zend_string *str2 = zval_get_string(op2);
1694-
1695-
ZVAL_LONG(result, zend_binary_strcmp(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str2)));
1695+
int ret = zend_binary_strcmp(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str2));
16961696

16971697
zend_string_release(str1);
16981698
zend_string_release(str2);
1699+
return ret;
16991700
}
1700-
return SUCCESS;
17011701
}
17021702
/* }}} */
17031703

1704-
ZEND_API int string_case_compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
1704+
ZEND_API int ZEND_FASTCALL string_case_compare_function(zval *op1, zval *op2) /* {{{ */
17051705
{
17061706
if (EXPECTED(Z_TYPE_P(op1) == IS_STRING) &&
17071707
EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
17081708
if (Z_STR_P(op1) == Z_STR_P(op2)) {
1709-
ZVAL_LONG(result, 0);
1709+
return 0;
17101710
} else {
1711-
ZVAL_LONG(result, zend_binary_strcasecmp_l(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2)));
1711+
return zend_binary_strcasecmp_l(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
17121712
}
17131713
} else {
17141714
zend_string *str1 = zval_get_string(op1);
17151715
zend_string *str2 = zval_get_string(op2);
1716-
1717-
ZVAL_LONG(result, zend_binary_strcasecmp_l(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str1)));
1716+
int ret = zend_binary_strcasecmp_l(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str1));
17181717

17191718
zend_string_release(str1);
17201719
zend_string_release(str2);
1720+
return ret;
17211721
}
1722-
return SUCCESS;
17231722
}
17241723
/* }}} */
17251724

17261725
#if HAVE_STRCOLL
1727-
ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
1726+
ZEND_API int ZEND_FASTCALL string_locale_compare_function(zval *op1, zval *op2) /* {{{ */
17281727
{
17291728
zend_string *str1 = zval_get_string(op1);
17301729
zend_string *str2 = zval_get_string(op2);
1731-
1732-
ZVAL_LONG(result, strcoll(ZSTR_VAL(str1), ZSTR_VAL(str2)));
1730+
int ret = strcoll(ZSTR_VAL(str1), ZSTR_VAL(str2));
17331731

17341732
zend_string_release(str1);
17351733
zend_string_release(str2);
1736-
return SUCCESS;
1734+
return ret;
17371735
}
17381736
/* }}} */
17391737
#endif
17401738

1741-
ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
1739+
ZEND_API int ZEND_FASTCALL numeric_compare_function(zval *op1, zval *op2) /* {{{ */
17421740
{
17431741
double d1, d2;
17441742

17451743
d1 = zval_get_double(op1);
17461744
d2 = zval_get_double(op2);
17471745

1748-
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(d1 - d2));
1749-
1750-
return SUCCESS;
1746+
return ZEND_NORMALIZE_BOOL(d1 - d2);
17511747
}
17521748
/* }}} */
17531749

@@ -1763,7 +1759,7 @@ static inline void zend_free_obj_get_result(zval *op) /* {{{ */
17631759
}
17641760
/* }}} */
17651761

1766-
static int ZEND_FASTCALL convert_compare_result_to_long(zval *result)
1762+
static void ZEND_FASTCALL convert_compare_result_to_long(zval *result)
17671763
{
17681764
if (Z_TYPE_P(result) == IS_DOUBLE) {
17691765
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
@@ -1829,7 +1825,7 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
18291825
ZVAL_LONG(result, 0);
18301826
return SUCCESS;
18311827
}
1832-
ZVAL_LONG(result, zendi_smart_strcmp(op1, op2));
1828+
ZVAL_LONG(result, zendi_smart_strcmp(Z_STR_P(op1), Z_STR_P(op2)));
18331829
return SUCCESS;
18341830

18351831
case TYPE_PAIR(IS_NULL, IS_STRING):
@@ -1962,15 +1958,6 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
19621958
}
19631959
/* }}} */
19641960

1965-
ZEND_API int zval_compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
1966-
{
1967-
int ret = compare_function(result, op1, op2);
1968-
1969-
ZEND_ASSERT(Z_TYPE_P(result) == IS_LONG);
1970-
return ret;
1971-
}
1972-
/* }}} */
1973-
19741961
static int hash_zval_identical_function(zval *z1, zval *z2) /* {{{ */
19751962
{
19761963
zval result;
@@ -2644,15 +2631,15 @@ ZEND_API int ZEND_FASTCALL zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval
26442631
}
26452632
/* }}} */
26462633

2647-
ZEND_API zend_long ZEND_FASTCALL zendi_smart_strcmp(zval *s1, zval *s2) /* {{{ */
2634+
ZEND_API zend_long ZEND_FASTCALL zendi_smart_strcmp(zend_string *s1, zend_string *s2) /* {{{ */
26482635
{
26492636
int ret1, ret2;
26502637
int oflow1, oflow2;
26512638
zend_long lval1 = 0, lval2 = 0;
26522639
double dval1 = 0.0, dval2 = 0.0;
26532640

2654-
if ((ret1 = is_numeric_string_ex(Z_STRVAL_P(s1), Z_STRLEN_P(s1), &lval1, &dval1, 0, &oflow1)) &&
2655-
(ret2 = is_numeric_string_ex(Z_STRVAL_P(s2), Z_STRLEN_P(s2), &lval2, &dval2, 0, &oflow2))) {
2641+
if ((ret1 = is_numeric_string_ex(s1->val, s1->len, &lval1, &dval1, 0, &oflow1)) &&
2642+
(ret2 = is_numeric_string_ex(s2->val, s2->len, &lval2, &dval2, 0, &oflow2))) {
26562643
#if ZEND_ULONG_MAX == 0xFFFFFFFF
26572644
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0. &&
26582645
((oflow1 == 1 && dval1 > 9007199254740991. /*0x1FFFFFFFFFFFFF*/)
@@ -2689,7 +2676,7 @@ ZEND_API zend_long ZEND_FASTCALL zendi_smart_strcmp(zval *s1, zval *s2) /* {{{ *
26892676
} else {
26902677
int strcmp_ret;
26912678
string_cmp:
2692-
strcmp_ret = zend_binary_strcmp(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2));
2679+
strcmp_ret = zend_binary_strcmp(s1->val, s1->len, s2->val, s2->len);
26932680
return ZEND_NORMALIZE_BOOL(strcmp_ret);
26942681
}
26952682
}

Zend/zend_operators.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,13 @@ static zend_always_inline int i_zend_is_true(zval *op)
329329
}
330330

331331
ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2);
332-
ZEND_API int zval_compare_function(zval *result, zval *op1, zval *op2);
333-
ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2);
334-
ZEND_API int string_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive);
335-
ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2);
336-
ZEND_API int string_case_compare_function(zval *result, zval *op1, zval *op2);
332+
333+
ZEND_API int ZEND_FASTCALL numeric_compare_function(zval *op1, zval *op2);
334+
ZEND_API int ZEND_FASTCALL string_compare_function_ex(zval *op1, zval *op2, zend_bool case_insensitive);
335+
ZEND_API int ZEND_FASTCALL string_compare_function(zval *op1, zval *op2);
336+
ZEND_API int ZEND_FASTCALL string_case_compare_function(zval *op1, zval *op2);
337337
#if HAVE_STRCOLL
338-
ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2);
338+
ZEND_API int ZEND_FASTCALL string_locale_compare_function(zval *op1, zval *op2);
339339
#endif
340340

341341
ZEND_API void ZEND_FASTCALL zend_str_tolower(char *str, size_t length);
@@ -355,7 +355,7 @@ ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp(const char *s1, size_t len1,
355355
ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2);
356356
ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2, size_t length);
357357

358-
ZEND_API zend_long ZEND_FASTCALL zendi_smart_strcmp(zval *s1, zval *s2);
358+
ZEND_API zend_long ZEND_FASTCALL zendi_smart_strcmp(zend_string *s1, zend_string *s2);
359359
ZEND_API int ZEND_FASTCALL zend_compare_symbol_tables(HashTable *ht1, HashTable *ht2);
360360
ZEND_API int ZEND_FASTCALL zend_compare_arrays(zval *a1, zval *a2);
361361
ZEND_API int ZEND_FASTCALL zend_compare_objects(zval *o1, zval *o2);
@@ -692,7 +692,7 @@ static zend_always_inline int fast_equal_check_function(zval *op1, zval *op2)
692692
return memcmp(Z_STRVAL_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op1)) == 0;
693693
}
694694
} else {
695-
return zendi_smart_strcmp(op1, op2) == 0;
695+
return zendi_smart_strcmp(Z_STR_P(op1), Z_STR_P(op2)) == 0;
696696
}
697697
}
698698
}
@@ -723,7 +723,7 @@ static zend_always_inline int fast_equal_check_string(zval *op1, zval *op2)
723723
return memcmp(Z_STRVAL_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op1)) == 0;
724724
}
725725
} else {
726-
return zendi_smart_strcmp(op1, op2) == 0;
726+
return zendi_smart_strcmp(Z_STR_P(op1), Z_STR_P(op2)) == 0;
727727
}
728728
}
729729
compare_function(&result, op1, op2);

Zend/zend_vm_def.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ ZEND_VM_HANDLER(17, ZEND_IS_EQUAL, CONST|TMPVAR|CV, CONST|TMPVAR|CV)
380380
result = (memcmp(Z_STRVAL_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op1)) == 0);
381381
}
382382
} else {
383-
result = (zendi_smart_strcmp(op1, op2) == 0);
383+
result = (zendi_smart_strcmp(Z_STR_P(op1), Z_STR_P(op2)) == 0);
384384
}
385385
FREE_OP1();
386386
FREE_OP2();
@@ -448,7 +448,7 @@ ZEND_VM_HANDLER(18, ZEND_IS_NOT_EQUAL, CONST|TMPVAR|CV, CONST|TMPVAR|CV)
448448
result = (memcmp(Z_STRVAL_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op1)) != 0);
449449
}
450450
} else {
451-
result = (zendi_smart_strcmp(op1, op2) != 0);
451+
result = (zendi_smart_strcmp(Z_STR_P(op1), Z_STR_P(op2)) != 0);
452452
}
453453
FREE_OP1();
454454
FREE_OP2();
@@ -4832,7 +4832,7 @@ ZEND_VM_HANDLER(48, ZEND_CASE, CONST|TMPVAR|CV, CONST|TMPVAR|CV)
48324832
result = (memcmp(Z_STRVAL_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op1)) == 0);
48334833
}
48344834
} else {
4835-
result = (zendi_smart_strcmp(op1, op2) == 0);
4835+
result = (zendi_smart_strcmp(Z_STR_P(op1), Z_STR_P(op2)) == 0);
48364836
}
48374837
FREE_OP2();
48384838
} else {

0 commit comments

Comments
 (0)