From a389a3ae7f1bd6082ea1f8d4b1493def73221db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Sun, 4 Dec 2022 18:36:34 +0100 Subject: [PATCH] Simplify CpuInfoFinder (#26) --- src/CpuInfoFinder.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CpuInfoFinder.php b/src/CpuInfoFinder.php index 9693dbf..bc6321e 100644 --- a/src/CpuInfoFinder.php +++ b/src/CpuInfoFinder.php @@ -13,9 +13,9 @@ namespace Fidry\CpuCounter; -use function count; use function file_get_contents; use function is_file; +use function mb_substr_count; /** * Find the number of CPU cores looking up at the cpuinfo file which is available @@ -58,9 +58,7 @@ private static function getCpuInfo(): ?string */ public static function countCpuCores(string $cpuInfo): ?int { - preg_match_all('/^processor/m', $cpuInfo, $matches); - - $processorCount = count($matches[0]); + $processorCount = mb_substr_count($cpuInfo, 'processor'); return $processorCount > 0 ? $processorCount : null; }