Use str_starts_with and str_contains instead of strpos (#5482)

This commit is contained in:
Alexey
2022-12-31 00:41:30 +03:00
committed by GitHub
parent 0d169b4e80
commit 0d31b25fba
6 changed files with 18 additions and 16 deletions

View File

@ -38,8 +38,8 @@ use function posix_kill;
use function preg_match;
use function proc_close;
use function proc_open;
use function str_starts_with;
use function stream_get_contents;
use function strpos;
use function trim;
final class Process{
@ -99,9 +99,9 @@ final class Process{
if($mappings === false) throw new AssumptionFailedError("/proc/self/maps should always be accessible");
foreach($mappings as $line){
if(preg_match("#([a-z0-9]+)\\-([a-z0-9]+) [rwxp\\-]{4} [a-z0-9]+ [^\\[]*\\[([a-zA-z0-9]+)\\]#", trim($line), $matches) > 0){
if(strpos($matches[3], "heap") === 0){
if(str_starts_with($matches[3], "heap")){
$heap += (int) hexdec($matches[2]) - (int) hexdec($matches[1]);
}elseif(strpos($matches[3], "stack") === 0){
}elseif(str_starts_with($matches[3], "stack")){
$stack += (int) hexdec($matches[2]) - (int) hexdec($matches[1]);
}
}