@@ -831,8 +831,15 @@ SampleProfileReaderExtBinaryBase::read(const DenseSet<StringRef> &FuncsToUse,
831831 if (std::error_code EC = readFuncProfiles (FuncsToUse, Profiles))
832832 return EC;
833833 End = Data;
834+ DenseSet<FunctionSamples *> ProfilesToReadMetadata;
835+ for (auto FName : FuncsToUse) {
836+ auto I = Profiles.find (FName);
837+ if (I != Profiles.end ())
838+ ProfilesToReadMetadata.insert (&I->second );
839+ }
834840
835- if (std::error_code EC = readFuncMetadata (ProfileHasAttribute, Profiles))
841+ if (std::error_code EC =
842+ readFuncMetadata (ProfileHasAttribute, ProfilesToReadMetadata))
836843 return EC;
837844 return sampleprof_error::success;
838845}
@@ -1300,14 +1307,12 @@ SampleProfileReaderExtBinaryBase::readFuncMetadata(bool ProfileHasAttribute,
13001307 return sampleprof_error::success;
13011308}
13021309
1303- std::error_code
1304- SampleProfileReaderExtBinaryBase::readFuncMetadata (bool ProfileHasAttribute,
1305- SampleProfileMap &Profiles) {
1310+ std::error_code SampleProfileReaderExtBinaryBase::readFuncMetadata (
1311+ bool ProfileHasAttribute, DenseSet<FunctionSamples *> &Profiles) {
13061312 if (FuncMetadataIndex.empty ())
13071313 return sampleprof_error::success;
13081314
1309- for (auto &I : Profiles) {
1310- FunctionSamples *FProfile = &I.second ;
1315+ for (auto *FProfile : Profiles) {
13111316 auto R = FuncMetadataIndex.find (FProfile->getContext ().getHashCode ());
13121317 if (R == FuncMetadataIndex.end ())
13131318 continue ;
0 commit comments