Skip to content

Commit be60afe

Browse files
authored
[clang][modules] De-duplicate some logic in HeaderFileInfoTrait (llvm#114330)
1 parent 6582785 commit be60afe

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
@@ -2042,19 +2042,15 @@ ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M,
20422042
return LocalID + I->second;
20432043
}
20442044

2045-
const FileEntry *HeaderFileInfoTrait::getFile(const internal_key_type &Key) {
2045+
OptionalFileEntryRef
2046+
HeaderFileInfoTrait::getFile(const internal_key_type &Key) {
20462047
FileManager &FileMgr = Reader.getFileManager();
2047-
if (!Key.Imported) {
2048-
if (auto File = FileMgr.getOptionalFileRef(Key.Filename))
2049-
return *File;
2050-
return nullptr;
2051-
}
2048+
if (!Key.Imported)
2049+
return FileMgr.getOptionalFileRef(Key.Filename);
20522050

20532051
std::string Resolved = std::string(Key.Filename);
20542052
Reader.ResolveImportedPath(M, Resolved);
2055-
if (auto File = FileMgr.getOptionalFileRef(Resolved))
2056-
return *File;
2057-
return nullptr;
2053+
return FileMgr.getOptionalFileRef(Resolved);
20582054
}
20592055

20602056
unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) {
@@ -2080,8 +2076,8 @@ bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) {
20802076
return true;
20812077

20822078
// Determine whether the actual files are equivalent.
2083-
const FileEntry *FEA = getFile(a);
2084-
const FileEntry *FEB = getFile(b);
2079+
OptionalFileEntryRef FEA = getFile(a);
2080+
OptionalFileEntryRef FEB = getFile(b);
20852081
return FEA && FEA == FEB;
20862082
}
20872083

@@ -2112,12 +2108,13 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
21122108
HeaderFileInfo HFI;
21132109
unsigned Flags = *d++;
21142110

2111+
OptionalFileEntryRef FE;
21152112
bool Included = (Flags >> 6) & 0x01;
21162113
if (Included)
2117-
if (const FileEntry *FE = getFile(key))
2114+
if ((FE = getFile(key)))
21182115
// Not using \c Preprocessor::markIncluded(), since that would attempt to
21192116
// deserialize this header file info again.
2120-
Reader.getPreprocessor().getIncludedFiles().insert(FE);
2117+
Reader.getPreprocessor().getIncludedFiles().insert(*FE);
21212118

21222119
// FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp.
21232120
HFI.isImport |= (Flags >> 5) & 0x01;
@@ -2146,14 +2143,10 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
21462143
// implicit module import.
21472144
SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID);
21482145
Module *Mod = Reader.getSubmodule(GlobalSMID);
2149-
FileManager &FileMgr = Reader.getFileManager();
21502146
ModuleMap &ModMap =
21512147
Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap();
21522148

2153-
std::string Filename = std::string(key.Filename);
2154-
if (key.Imported)
2155-
Reader.ResolveImportedPath(M, Filename);
2156-
if (auto FE = FileMgr.getOptionalFileRef(Filename)) {
2149+
if (FE || (FE = getFile(key))) {
21572150
// FIXME: NameAsWritten
21582151
Module::Header H = {std::string(key.Filename), "", *FE};
21592152
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)