1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[Symbolize] Avoid lifetime extension and simplify std::map find/insert. NFC

llvm-svn: 364025
This commit is contained in:
Fangrui Song 2019-06-21 11:05:26 +00:00
parent c40e3f2037
commit ff211fcdea

View File

@ -304,15 +304,14 @@ ObjectFile *LLVMSymbolizer::lookUpDebuglinkObject(const std::string &Path,
Expected<LLVMSymbolizer::ObjectPair>
LLVMSymbolizer::getOrCreateObjectPair(const std::string &Path,
const std::string &ArchName) {
const auto &I = ObjectPairForPathArch.find(std::make_pair(Path, ArchName));
if (I != ObjectPairForPathArch.end()) {
auto I = ObjectPairForPathArch.find(std::make_pair(Path, ArchName));
if (I != ObjectPairForPathArch.end())
return I->second;
}
auto ObjOrErr = getOrCreateObject(Path, ArchName);
if (!ObjOrErr) {
ObjectPairForPathArch.insert(std::make_pair(std::make_pair(Path, ArchName),
ObjectPair(nullptr, nullptr)));
ObjectPairForPathArch.emplace(std::make_pair(Path, ArchName),
ObjectPair(nullptr, nullptr));
return ObjOrErr.takeError();
}
@ -327,46 +326,43 @@ LLVMSymbolizer::getOrCreateObjectPair(const std::string &Path,
if (!DbgObj)
DbgObj = Obj;
ObjectPair Res = std::make_pair(Obj, DbgObj);
ObjectPairForPathArch.insert(
std::make_pair(std::make_pair(Path, ArchName), Res));
ObjectPairForPathArch.emplace(std::make_pair(Path, ArchName), Res);
return Res;
}
Expected<ObjectFile *>
LLVMSymbolizer::getOrCreateObject(const std::string &Path,
const std::string &ArchName) {
const auto &I = BinaryForPath.find(Path);
Binary *Bin = nullptr;
if (I == BinaryForPath.end()) {
Expected<OwningBinary<Binary>> BinOrErr = createBinary(Path);
if (!BinOrErr) {
BinaryForPath.insert(std::make_pair(Path, OwningBinary<Binary>()));
return BinOrErr.takeError();
}
Bin = BinOrErr->getBinary();
BinaryForPath.insert(std::make_pair(Path, std::move(BinOrErr.get())));
Binary *Bin;
auto Pair = BinaryForPath.emplace(Path, OwningBinary<Binary>());
if (!Pair.second) {
Bin = Pair.first->second.getBinary();
} else {
Bin = I->second.getBinary();
Expected<OwningBinary<Binary>> BinOrErr = createBinary(Path);
if (!BinOrErr)
return BinOrErr.takeError();
Pair.first->second = std::move(BinOrErr.get());
Bin = Pair.first->second.getBinary();
}
if (!Bin)
return static_cast<ObjectFile *>(nullptr);
if (MachOUniversalBinary *UB = dyn_cast_or_null<MachOUniversalBinary>(Bin)) {
const auto &I = ObjectForUBPathAndArch.find(std::make_pair(Path, ArchName));
if (I != ObjectForUBPathAndArch.end()) {
auto I = ObjectForUBPathAndArch.find(std::make_pair(Path, ArchName));
if (I != ObjectForUBPathAndArch.end())
return I->second.get();
}
Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
UB->getObjectForArch(ArchName);
if (!ObjOrErr) {
ObjectForUBPathAndArch.insert(std::make_pair(
std::make_pair(Path, ArchName), std::unique_ptr<ObjectFile>()));
ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName),
std::unique_ptr<ObjectFile>());
return ObjOrErr.takeError();
}
ObjectFile *Res = ObjOrErr->get();
ObjectForUBPathAndArch.insert(std::make_pair(std::make_pair(Path, ArchName),
std::move(ObjOrErr.get())));
ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName),
std::move(ObjOrErr.get()));
return Res;
}
if (Bin->isObject()) {
@ -377,10 +373,10 @@ LLVMSymbolizer::getOrCreateObject(const std::string &Path,
Expected<SymbolizableModule *>
LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
const auto &I = Modules.find(ModuleName);
if (I != Modules.end()) {
auto I = Modules.find(ModuleName);
if (I != Modules.end())
return I->second.get();
}
std::string BinaryName = ModuleName;
std::string ArchName = Opts.DefaultArch;
size_t ColonPos = ModuleName.find_last_of(':');
@ -395,8 +391,7 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
auto ObjectsOrErr = getOrCreateObjectPair(BinaryName, ArchName);
if (!ObjectsOrErr) {
// Failed to find valid object file.
Modules.insert(
std::make_pair(ModuleName, std::unique_ptr<SymbolizableModule>()));
Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
return ObjectsOrErr.takeError();
}
ObjectPair Objects = ObjectsOrErr.get();
@ -413,8 +408,7 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
std::unique_ptr<IPDBSession> Session;
if (auto Err = loadDataForEXE(PDB_ReaderType::DIA,
Objects.first->getFileName(), Session)) {
Modules.insert(
std::make_pair(ModuleName, std::unique_ptr<SymbolizableModule>()));
Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
// Return along the PDB filename to provide more context
return createFileError(PDBFileName, std::move(Err));
}
@ -430,8 +424,7 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
std::unique_ptr<SymbolizableModule> SymMod;
if (InfoOrErr)
SymMod = std::move(InfoOrErr.get());
auto InsertResult =
Modules.insert(std::make_pair(ModuleName, std::move(SymMod)));
auto InsertResult = Modules.emplace(ModuleName, std::move(SymMod));
assert(InsertResult.second);
if (auto EC = InfoOrErr.getError())
return errorCodeToError(EC);