Skip to content

Commit 9db0258

Browse files
committed
[clang][modules] De-duplicate some logic in HeaderFileInfoTrait (llvm#114330)
(cherry picked from commit be60afe)
1 parent 397c2ee commit 9db0258

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

clang/lib/Serialization/ASTReader.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,19 +2031,15 @@ ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M,
20312031
return LocalID + I->second;
20322032
}
20332033

2034-
const FileEntry *HeaderFileInfoTrait::getFile(const internal_key_type &Key) {
2034+
OptionalFileEntryRef
2035+
HeaderFileInfoTrait::getFile(const internal_key_type &Key) {
20352036
FileManager &FileMgr = Reader.getFileManager();
2036-
if (!Key.Imported) {
2037-
if (auto File = FileMgr.getFile(Key.Filename))
2038-
return *File;
2039-
return nullptr;
2040-
}
2037+
if (!Key.Imported)
2038+
return FileMgr.getOptionalFileRef(Key.Filename);
20412039

20422040
std::string Resolved = std::string(Key.Filename);
20432041
Reader.ResolveImportedPath(M, Resolved);
2044-
if (auto File = FileMgr.getFile(Resolved))
2045-
return *File;
2046-
return nullptr;
2042+
return FileMgr.getOptionalFileRef(Resolved);
20472043
}
20482044

20492045
unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) {
@@ -2069,8 +2065,8 @@ bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) {
20692065
return true;
20702066

20712067
// Determine whether the actual files are equivalent.
2072-
const FileEntry *FEA = getFile(a);
2073-
const FileEntry *FEB = getFile(b);
2068+
OptionalFileEntryRef FEA = getFile(a);
2069+
OptionalFileEntryRef FEB = getFile(b);
20742070
return FEA && FEA == FEB;
20752071
}
20762072

@@ -2101,12 +2097,13 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
21012097
HeaderFileInfo HFI;
21022098
unsigned Flags = *d++;
21032099

2100+
OptionalFileEntryRef FE;
21042101
bool Included = (Flags >> 6) & 0x01;
21052102
if (Included)
2106-
if (const FileEntry *FE = getFile(key))
2103+
if ((FE = getFile(key)))
21072104
// Not using \c Preprocessor::markIncluded(), since that would attempt to
21082105
// deserialize this header file info again.
2109-
Reader.getPreprocessor().getIncludedFiles().insert(FE);
2106+
Reader.getPreprocessor().getIncludedFiles().insert(*FE);
21102107

21112108
// FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp.
21122109
HFI.isImport |= (Flags >> 5) & 0x01;
@@ -2135,14 +2132,10 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
21352132
// implicit module import.
21362133
SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID);
21372134
Module *Mod = Reader.getSubmodule(GlobalSMID);
2138-
FileManager &FileMgr = Reader.getFileManager();
21392135
ModuleMap &ModMap =
21402136
Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap();
21412137

2142-
std::string Filename = std::string(key.Filename);
2143-
if (key.Imported)
2144-
Reader.ResolveImportedPath(M, Filename);
2145-
if (auto FE = FileMgr.getOptionalFileRef(Filename)) {
2138+
if (FE || (FE = getFile(key))) {
21462139
// FIXME: NameAsWritten
21472140
Module::Header H = {std::string(key.Filename), "", *FE};
21482141
ModMap.addHeader(Mod, H, HeaderRole, /*Imported=*/true);

clang/lib/Serialization/ASTReaderInternals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class HeaderFileInfoTrait {
278278
data_type ReadData(internal_key_ref,const unsigned char *d, unsigned DataLen);
279279

280280
private:
281-
const FileEntry *getFile(const internal_key_type &Key);
281+
OptionalFileEntryRef getFile(const internal_key_type &Key);
282282
};
283283

284284
/// The on-disk hash table used for known header files.

0 commit comments

Comments
 (0)