Skip to content

Commit adefcbf

Browse files
authored
NodeDependencies: cache normalized filenames (#4815)
1 parent ef7e5b9 commit adefcbf

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/File/FileHelper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
final class FileHelper
2525
{
2626

27+
/** @var array<string, array<string, string>> */
28+
private static array $normalizedPathsCache = [];
29+
2730
private string $workingDirectory;
2831

2932
public function __construct(
@@ -60,6 +63,11 @@ public function absolutizePath(string $path): string
6063
/** @api */
6164
public function normalizePath(string $originalPath, string $directorySeparator = DIRECTORY_SEPARATOR): string
6265
{
66+
$cached = self::$normalizedPathsCache[$originalPath][$directorySeparator] ?? null;
67+
if ($cached !== null) {
68+
return $cached;
69+
}
70+
6371
$isLocalPath = false;
6472
if ($originalPath !== '') {
6573
if ($originalPath[0] === '/') {
@@ -102,7 +110,7 @@ public function normalizePath(string $originalPath, string $directorySeparator =
102110
}
103111
}
104112

105-
return ($scheme !== null ? $scheme . '://' : '') . $pathRoot . implode($directorySeparator, $normalizedPathParts);
113+
return self::$normalizedPathsCache[$originalPath][$directorySeparator] = ($scheme !== null ? $scheme . '://' : '') . $pathRoot . implode($directorySeparator, $normalizedPathParts);
106114
}
107115

108116
}

0 commit comments

Comments
 (0)