Skip to content

Commit c4d8154

Browse files
committed
ext/standard: Simplify SORT_STRICT type comparison
1 parent 0250dac commit c4d8154

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

ext/standard/array.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -359,23 +359,6 @@ static int php_array_data_compare_string_locale_unstable_i(Bucket *f, Bucket *s)
359359
}
360360
/* }}} */
361361

362-
/* Returns the position of a PHP type in the total ordering used by SORT_STRICT. */
363-
static zend_always_inline int php_array_type_order(uint8_t type)
364-
{
365-
switch (type) {
366-
case IS_NULL: return 0;
367-
case IS_FALSE: return 1;
368-
case IS_TRUE: return 2;
369-
case IS_LONG: return 3;
370-
case IS_DOUBLE: return 4;
371-
case IS_STRING: return 5;
372-
case IS_ARRAY: return 6;
373-
case IS_OBJECT: return 7;
374-
case IS_RESOURCE: return 8;
375-
EMPTY_SWITCH_DEFAULT_CASE()
376-
}
377-
}
378-
379362
static zend_always_inline int php_array_compare_strings(zend_string *s1, zend_string *s2)
380363
{
381364
if (s1 == s2) {
@@ -441,7 +424,8 @@ static int php_array_sort_compare_objects_strict(zval *o1, zval *o2)
441424
return Z_OBJ_HT_P(o1)->compare(o1, o2);
442425
}
443426

444-
/* Compare declared properties directly when no dynamic properties exist */
427+
/* Compare declared properties directly when no dynamic properties exist.
428+
* Lazy objects are excluded so they get initialized via zend_std_get_properties_ex(). */
445429
if (!zobj1->properties && !zobj2->properties
446430
&& !zend_object_is_lazy(zobj1) && !zend_object_is_lazy(zobj2)) {
447431
zend_property_info *info;
@@ -555,11 +539,7 @@ static zend_always_inline int php_array_sort_compare_strict(zval *op1, zval *op2
555539
}
556540

557541
/* Types differ: order by type hierarchy */
558-
/* Special case: IS_FALSE (2) and IS_TRUE (3) are both bool, so compare by value */
559-
if ((t1 | 1) == IS_TRUE && (t2 | 1) == IS_TRUE) {
560-
return t1 > t2 ? 1 : -1;
561-
}
562-
return php_array_type_order(t1) > php_array_type_order(t2) ? 1 : -1;
542+
return t1 > t2 ? 1 : -1;
563543
}
564544

565545
static zend_always_inline int php_array_data_compare_strict_unstable_i(Bucket *f, Bucket *s)

0 commit comments

Comments
 (0)