@@ -62,12 +62,16 @@ static ExceptionOr<Vector<ListedChild>> listDirectoryWithMetadata(const String&
6262 return Exception { NotFoundError, " Path no longer exists or is no longer a directory" _s };
6363
6464 auto childNames = FileSystem::listDirectory (fullPath);
65- return WTF::compactMap (WTFMove (childNames), [&](auto && childName) -> std::optional<ListedChild> {
65+ Vector<ListedChild> listedChildren;
66+ listedChildren.reserveInitialCapacity (childNames.size ());
67+ for (auto & childName : childNames) {
6668 auto childPath = FileSystem::pathByAppendingComponent (fullPath, childName);
67- if (auto fileType = fileTypeIgnoringHiddenFiles (childPath))
68- return ListedChild { WTFMove (childName), *fileType };
69- return std::nullopt ;
70- });
69+ auto fileType = fileTypeIgnoringHiddenFiles (childPath);
70+ if (!fileType)
71+ continue ;
72+ listedChildren.uncheckedAppend (ListedChild { childName, *fileType });
73+ }
74+ return listedChildren;
7175}
7276
7377static ExceptionOr<Vector<Ref<FileSystemEntry>>> toFileSystemEntries (ScriptExecutionContext& context, DOMFileSystem& fileSystem, ExceptionOr<Vector<ListedChild>>&& listedChildren, const String& parentVirtualPath)
@@ -76,18 +80,22 @@ static ExceptionOr<Vector<Ref<FileSystemEntry>>> toFileSystemEntries(ScriptExecu
7680 if (listedChildren.hasException ())
7781 return listedChildren.releaseException ();
7882
79- return WTF::compactMap (listedChildren.returnValue (), [&](auto & child) -> RefPtr<FileSystemEntry> {
83+ Vector<Ref<FileSystemEntry>> entries;
84+ entries.reserveInitialCapacity (listedChildren.returnValue ().size ());
85+ for (auto & child : listedChildren.returnValue ()) {
8086 String virtualPath = parentVirtualPath + " /" + child.filename ;
8187 switch (child.type ) {
8288 case FileSystem::FileType::Regular:
83- return FileSystemFileEntry::create (context, fileSystem, virtualPath);
89+ entries.uncheckedAppend (FileSystemFileEntry::create (context, fileSystem, virtualPath));
90+ break ;
8491 case FileSystem::FileType::Directory:
85- return FileSystemDirectoryEntry::create (context, fileSystem, virtualPath);
92+ entries.uncheckedAppend (FileSystemDirectoryEntry::create (context, fileSystem, virtualPath));
93+ break ;
8694 default :
8795 break ;
8896 }
89- return nullptr ;
90- }) ;
97+ }
98+ return entries ;
9199}
92100
93101// https://wicg.github.io/entries-api/#name
0 commit comments