Skip to content

Commit 2a8eaaf

Browse files
committed
[Serialization] Avoid to call getTargetSpecificModuleTriple() twice
Maintain an invariant that forEachTargetModuleBasename() iterates names from most to least desiable. (cherry picked from commit 0d43e5a)
1 parent 10ee164 commit 2a8eaaf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ using swift::version::Version;
3333

3434
namespace {
3535

36-
/// Apply \c body for each target-specific module file base name to search.
36+
/// Apply \c body for each target-specific module file base name to search from
37+
/// most to least desiable.
3738
void forEachTargetModuleBasename(const ASTContext &Ctx,
3839
llvm::function_ref<void(StringRef)> body) {
3940
auto normalizedTarget = getTargetSpecificModuleTriple(Ctx.LangOpts.Target);
@@ -373,8 +374,11 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
373374
ModuleFilenamePair fileNames(moduleName);
374375

375376
SmallVector<ModuleFilenamePair, 4> targetFileNamePairs;
377+
SmallString<32> primaryTargetSpecificName;
376378
forEachTargetModuleBasename(Ctx, [&](StringRef targetName) {
377379
targetFileNamePairs.emplace_back(targetName);
380+
if (primaryTargetSpecificName.empty())
381+
primaryTargetSpecificName = targetName;
378382
});
379383

380384
auto &fs = *Ctx.SourceMgr.getFileSystem();
@@ -400,9 +404,8 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
400404

401405
// We can only get here if all targetFileNamePairs failed with
402406
// 'std::errc::no_such_file_or_directory'.
403-
auto normalizedTarget = getTargetSpecificModuleTriple(Ctx.LangOpts.Target);
404407
if (maybeDiagnoseTargetMismatch(moduleID.second, moduleName,
405-
normalizedTarget.str(), currPath)) {
408+
primaryTargetSpecificName, currPath)) {
406409
return false;
407410
} else {
408411
return None;

0 commit comments

Comments
 (0)