[Serialization] Avoid to call getTargetSpecificModuleTriple() twice

Maintain an invariant that forEachTargetModuleBasename() iterates names
from most to least desiable.
This commit is contained in:
Rintaro Ishizaki
2019-05-08 10:21:57 -07:00
parent ffde2280c9
commit 0d43e5ad67

View File

@@ -33,7 +33,8 @@ using swift::version::Version;
namespace {
/// Apply \c body for each target-specific module file base name to search.
/// Apply \c body for each target-specific module file base name to search from
/// most to least desiable.
void forEachTargetModuleBasename(const ASTContext &Ctx,
llvm::function_ref<void(StringRef)> body) {
auto normalizedTarget = getTargetSpecificModuleTriple(Ctx.LangOpts.Target);
@@ -373,8 +374,11 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
ModuleFilenamePair fileNames(moduleName);
SmallVector<ModuleFilenamePair, 4> targetFileNamePairs;
SmallString<32> primaryTargetSpecificName;
forEachTargetModuleBasename(Ctx, [&](StringRef targetName) {
targetFileNamePairs.emplace_back(targetName);
if (primaryTargetSpecificName.empty())
primaryTargetSpecificName = targetName;
});
auto &fs = *Ctx.SourceMgr.getFileSystem();
@@ -400,9 +404,8 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
// We can only get here if all targetFileNamePairs failed with
// 'std::errc::no_such_file_or_directory'.
auto normalizedTarget = getTargetSpecificModuleTriple(Ctx.LangOpts.Target);
if (maybeDiagnoseTargetMismatch(moduleID.second, moduleName,
normalizedTarget.str(), currPath)) {
primaryTargetSpecificName, currPath)) {
return false;
} else {
return None;