Skip to content

Commit 75f063f

Browse files
committed
Performance optimizations.
1 parent d9bbd5d commit 75f063f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/DataListTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ private function internalDataListUpdateData($data, $actions): array
458458
$previous = null;
459459
foreach ($prefixes as $prefix) {
460460
if ($fromStart) {
461-
if ($previous === null || ($less ? strncmp($previous, $prefix, strlen($prefix)) !== 0 : strncmp($prefix, $previous, strlen($previous)) !== 0)) {
461+
if ($previous === null || ($less ? !str_starts_with($previous, $prefix) : !str_starts_with($prefix, $previous))) {
462462
$result[] = $prefix;
463463
$previous = $prefix;
464464
}
@@ -477,7 +477,7 @@ private function internalDataListUpdateData($data, $actions): array
477477
$found = false;
478478
foreach ($prefixes2 as $prefix2) {
479479
if ($fromStart) {
480-
if (strncmp($prefix1, $prefix2, strlen($prefix2)) === 0) {
480+
if (str_starts_with($prefix1, $prefix2)) {
481481
$found = true;
482482
break;
483483
}
@@ -500,7 +500,7 @@ private function internalDataListUpdateData($data, $actions): array
500500
$found = false;
501501
foreach ($prefixes2 as $prefix2) {
502502
if ($fromStart) {
503-
if (strncmp($prefix1, $prefix2, strlen($prefix2)) === 0) {
503+
if (str_starts_with($prefix1, $prefix2)) {
504504
$found = true;
505505
break;
506506
}
@@ -750,21 +750,21 @@ private function internalDataListUpdateData($data, $actions): array
750750
}
751751
} elseif ($operator === 'startWith') {
752752
if (is_string($targetValue)) {
753-
$add = strncmp($value, $targetValue, strlen($targetValue)) === 0;
753+
$add = str_starts_with($value, $targetValue);
754754
} else {
755755
throw new \Exception('The target value for ' . $operator . ' must be of type string!');
756756
}
757757
} elseif ($operator === 'notStartWith') {
758758
if (is_string($targetValue)) {
759-
$add = strncmp($value, $targetValue, strlen($targetValue)) !== 0;
759+
$add = !str_starts_with($value, $targetValue);
760760
} else {
761761
throw new \Exception('The target value for ' . $operator . ' must be of type string!');
762762
}
763763
} elseif ($operator === 'startWithAny') {
764764
$add = false;
765765
if (is_array($targetValue)) {
766766
foreach ($targetValue as $targetValueItem) {
767-
if (strncmp($value, $targetValueItem, strlen($targetValueItem)) === 0) {
767+
if (str_starts_with($value, $targetValueItem)) {
768768
$add = true;
769769
break;
770770
}

0 commit comments

Comments
 (0)