@@ -257,7 +257,7 @@ llvm::Error IncludeTree::FileList::forEachFileImpl(
257
257
return llvm::Error::success ();
258
258
259
259
if (Index < FileCount) {
260
- auto Include = getFile ( Ref);
260
+ auto Include = File::get ( getCAS (), Ref);
261
261
if (!Include)
262
262
return Include.takeError ();
263
263
return Callback (std::move (*Include), getFileSize (Index));
@@ -1036,54 +1036,66 @@ cas::createIncludeTreeFileSystem(IncludeTreeRoot &Root) {
1036
1036
if (!FileList)
1037
1037
return FileList.takeError ();
1038
1038
1039
- return createIncludeTreeFileSystem (Root.getCAS (), *FileList);
1039
+ std::vector<IncludeTree::FileList::FileEntry> Files;
1040
+ Files.reserve (FileList->getNumReferences ());
1041
+
1042
+ if (auto Err = FileList->forEachFile (
1043
+ [&](IncludeTree::File File, IncludeTree::FileList::FileSizeTy Size) {
1044
+ Files.push_back ({File.getRef (), Size});
1045
+ return llvm::Error::success ();
1046
+ }))
1047
+ return std::move (Err);
1048
+
1049
+ return createIncludeTreeFileSystem (Root.getCAS (), Files);
1040
1050
}
1041
1051
1042
1052
Expected<IntrusiveRefCntPtr<llvm::vfs::FileSystem>>
1043
- cas::createIncludeTreeFileSystem (llvm::cas::ObjectStore &CAS,
1044
- IncludeTree::FileList &FileList) {
1053
+ cas::createIncludeTreeFileSystem (
1054
+ llvm::cas::ObjectStore &CAS,
1055
+ llvm::ArrayRef<IncludeTree::FileList::FileEntry> List) {
1045
1056
// Map from FilenameRef to ContentsRef.
1046
1057
llvm::DenseMap<ObjectRef, ObjectRef> SeenContents;
1047
1058
1048
1059
IntrusiveRefCntPtr<IncludeTreeFileSystem> IncludeTreeFS =
1049
1060
new IncludeTreeFileSystem (CAS);
1050
- llvm::Error E = FileList.forEachFile (
1051
- [&](IncludeTree::File File,
1052
- IncludeTree::FileList::FileSizeTy Size) -> llvm::Error {
1053
- auto InsertPair = SeenContents.insert (
1054
- std::make_pair (File.getFilenameRef (), File.getContentsRef ()));
1055
- if (!InsertPair.second ) {
1056
- if (InsertPair.first ->second != File.getContentsRef ())
1057
- return diagnoseFileChange (File, InsertPair.first ->second );
1058
- return llvm::Error::success ();
1059
- }
1060
-
1061
- auto FilenameBlob = File.getFilename ();
1062
- if (!FilenameBlob)
1063
- return FilenameBlob.takeError ();
1064
-
1065
- SmallString<128 > Filename (FilenameBlob->getData ());
1066
- // Strip './' in the filename to match the behaviour of ASTWriter; we
1067
- // also strip './' in IncludeTreeFileSystem::getPath.
1068
- assert (Filename != " ." );
1069
- llvm::sys::path::remove_dots (Filename);
1070
-
1071
- StringRef DirName = llvm::sys::path::parent_path (Filename);
1072
- if (DirName.empty ())
1073
- DirName = " ." ;
1074
- auto &DirEntry = IncludeTreeFS->Directories [DirName];
1075
- if (DirEntry == llvm::sys::fs::UniqueID ()) {
1076
- DirEntry = llvm::vfs::getNextVirtualUniqueID ();
1077
- }
1078
-
1079
- IncludeTreeFS->Files .insert (
1080
- std::make_pair (Filename, IncludeTreeFileSystem::FileEntry{
1081
- File.getContentsRef (), Size,
1061
+
1062
+ for (auto &Entry : List) {
1063
+ auto File = IncludeTree::File::get (CAS, Entry.FileRef );
1064
+
1065
+ if (!File)
1066
+ return File.takeError ();
1067
+
1068
+ auto InsertPair = SeenContents.insert (
1069
+ std::make_pair (File->getFilenameRef (), File->getContentsRef ()));
1070
+ if (!InsertPair.second ) {
1071
+ if (InsertPair.first ->second != File->getContentsRef ())
1072
+ return diagnoseFileChange (*File, InsertPair.first ->second );
1073
+ continue ;
1074
+ }
1075
+
1076
+ auto FilenameBlob = File->getFilename ();
1077
+ if (!FilenameBlob)
1078
+ return FilenameBlob.takeError ();
1079
+
1080
+ SmallString<128 > Filename (FilenameBlob->getData ());
1081
+ // Strip './' in the filename to match the behaviour of ASTWriter; we
1082
+ // also strip './' in IncludeTreeFileSystem::getPath.
1083
+ assert (Filename != " ." );
1084
+ llvm::sys::path::remove_dots (Filename);
1085
+
1086
+ StringRef DirName = llvm::sys::path::parent_path (Filename);
1087
+ if (DirName.empty ())
1088
+ DirName = " ." ;
1089
+ auto &DirEntry = IncludeTreeFS->Directories [DirName];
1090
+ if (DirEntry == llvm::sys::fs::UniqueID ()) {
1091
+ DirEntry = llvm::vfs::getNextVirtualUniqueID ();
1092
+ }
1093
+
1094
+ IncludeTreeFS->Files .insert (std::make_pair (
1095
+ Filename,
1096
+ IncludeTreeFileSystem::FileEntry{File->getContentsRef (), Entry.Size ,
1082
1097
llvm::vfs::getNextVirtualUniqueID ()}));
1083
- return llvm::Error::success ();
1084
- });
1085
- if (E)
1086
- return std::move (E);
1098
+ }
1087
1099
1088
1100
return IncludeTreeFS;
1089
1101
}
0 commit comments