Skip to content

Commit 0efe475

Browse files
ext/standard/array.c: remove some unreachable code
- If a `case` block always returns something, a `break` is unneeded - If every `case` block returns something, and there is a `default` block, then any code after the `switch` is unreachable, and can be replaced with `ZEND_UNREACHABLE()`
1 parent 1b9568d commit 0efe475

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

ext/standard/array.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int
445445
} else {
446446
return php_array_data_compare_numeric;
447447
}
448-
break;
449448

450449
case PHP_SORT_STRING:
451450
if (sort_type & PHP_SORT_FLAG_CASE) {
@@ -461,7 +460,6 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int
461460
return php_array_data_compare_string;
462461
}
463462
}
464-
break;
465463

466464
case PHP_SORT_NATURAL:
467465
if (sort_type & PHP_SORT_FLAG_CASE) {
@@ -477,15 +475,13 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int
477475
return php_array_natural_compare;
478476
}
479477
}
480-
break;
481478

482479
case PHP_SORT_LOCALE_STRING:
483480
if (reverse) {
484481
return php_array_reverse_data_compare_string_locale;
485482
} else {
486483
return php_array_data_compare_string_locale;
487484
}
488-
break;
489485

490486
case PHP_SORT_REGULAR:
491487
default:
@@ -494,9 +490,8 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int
494490
} else {
495491
return php_array_data_compare;
496492
}
497-
break;
498493
}
499-
return NULL;
494+
ZEND_UNREACHABLE();
500495
}
501496
/* }}} */
502497

@@ -509,7 +504,6 @@ static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_t
509504
} else {
510505
return php_array_data_compare_numeric_unstable;
511506
}
512-
break;
513507

514508
case PHP_SORT_STRING:
515509
if (sort_type & PHP_SORT_FLAG_CASE) {
@@ -525,7 +519,6 @@ static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_t
525519
return php_array_data_compare_string_unstable;
526520
}
527521
}
528-
break;
529522

530523
case PHP_SORT_NATURAL:
531524
if (sort_type & PHP_SORT_FLAG_CASE) {
@@ -541,15 +534,13 @@ static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_t
541534
return php_array_natural_compare_unstable;
542535
}
543536
}
544-
break;
545537

546538
case PHP_SORT_LOCALE_STRING:
547539
if (reverse) {
548540
return php_array_reverse_data_compare_string_locale_unstable;
549541
} else {
550542
return php_array_data_compare_string_locale_unstable;
551543
}
552-
break;
553544

554545
case PHP_SORT_REGULAR:
555546
default:
@@ -558,9 +549,8 @@ static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_t
558549
} else {
559550
return php_array_data_compare_unstable;
560551
}
561-
break;
562552
}
563-
return NULL;
553+
ZEND_UNREACHABLE();
564554
}
565555
/* }}} */
566556

0 commit comments

Comments
 (0)