File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ class Glob
2222 /** @var string The glob pattern */
2323 protected $ pattern ;
2424
25+ /** @var array Memoization cache */
26+ private $ cache = [];
27+
2528 /** @var string The directory separator */
2629 protected static $ directorySeparator = DIRECTORY_SEPARATOR ;
2730
@@ -104,6 +107,10 @@ public function reject(array $array): array
104107 /** Convert the glob a regular expression pattern. */
105108 public function toRegex (int $ options = self ::BOTH_ANCHORS ): string
106109 {
110+ if (isset ($ this ->cache [$ options ])) {
111+ return $ this ->cache [$ options ];
112+ }
113+
107114 $ pattern = '' ;
108115 $ characterGroup = 0 ;
109116 $ patternGroup = 0 ;
@@ -194,7 +201,7 @@ public function toRegex(int $options = self::BOTH_ANCHORS): string
194201 $ pattern = $ pattern . '$ ' ;
195202 }
196203
197- return sprintf ('#%s# ' , $ pattern );
204+ return $ this -> cache [ $ options ] = sprintf ('#%s# ' , $ pattern );
198205 }
199206
200207 /** Return the glob pattern as a string. */
You can’t perform that action at this time.
0 commit comments