2020class Manager implements IMountManager {
2121 /** @var array<string, IMountPoint> */
2222 private array $ mounts = [];
23+ private array $ mountsByProvider = [];
2324 private bool $ areMountsSorted = false ;
2425 /** @var list<string>|null $mountKeys */
2526 private ?array $ mountKeys = null ;
@@ -36,7 +37,11 @@ public function __construct(SetupManagerFactory $setupManagerFactory) {
3637 }
3738
3839 public function addMount (IMountPoint $ mount ): void {
39- $ this ->mounts [$ mount ->getMountPoint ()] = $ mount ;
40+ $ mountPoint = $ mount ->getMountPoint ();
41+ $ mountProvider = $ mount ->getMountProvider ();
42+ $ this ->mounts [$ mountPoint ] = $ mount ;
43+ $ this ->mountsByProvider [$ mountProvider ] ??= [];
44+ $ this ->mountsByProvider [$ mountProvider ][$ mountPoint ] = $ mount ;
4045 $ this ->pathCache ->clear ();
4146 $ this ->inPathCache ->clear ();
4247 $ this ->areMountsSorted = false ;
@@ -167,6 +172,7 @@ private function binarySearch(array $sortedArray, array $sortedKeys, string $pre
167172
168173 public function clear (): void {
169174 $ this ->mounts = [];
175+ $ this ->mountsByProvider = [];
170176 $ this ->pathCache ->clear ();
171177 $ this ->inPathCache ->clear ();
172178 }
@@ -236,15 +242,18 @@ public function getSetupManager(): SetupManager {
236242 * @param string[] $mountProviders
237243 * @return array<string, IMountPoint>
238244 */
239- public function getMountsByMountProvider (string $ path , array $ mountProviders ) {
245+ public function getMountsByMountProvider (string $ path , array $ mountProviders ): array {
240246 $ this ->getSetupManager ()->setupForProvider ($ path , $ mountProviders );
241- if (in_array ('' , $ mountProviders )) {
247+ if (\ in_array ('' , $ mountProviders )) {
242248 return $ this ->mounts ;
243- } else {
244- return array_filter ($ this ->mounts , function ($ mount ) use ($ mountProviders ) {
245- return in_array ($ mount ->getMountProvider (), $ mountProviders );
246- });
247249 }
250+
251+ $ mounts = [];
252+ foreach ($ mountProviders as $ mountProvider ) {
253+ $ mounts [] = $ this ->mountsByProvider [$ mountProvider ];
254+ }
255+
256+ return array_merge (...$ mounts );
248257 }
249258
250259 /**
0 commit comments