Skip to content

Commit b11e1ba

Browse files
[llvm-readtapi] Avoid repeated hash lookups (NFC) (llvm#128131)
Dylibs is a StringMap, which takes StringRef as the key type, so NormalizedPath.str() is good enough. We don't need to create a null terminated string. Neither do we need to recompute the string length as part of StringRef construction.
1 parent 8a58f83 commit b11e1ba

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

llvm/tools/llvm-readtapi/llvm-readtapi.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,19 @@ static void stubifyDirectory(const StringRef InputPath, Context &Ctx) {
358358
SmallString<PATH_MAX> NormalizedPath(Path);
359359
replace_extension(NormalizedPath, "");
360360

361+
auto [It, Inserted] = Dylibs.try_emplace(NormalizedPath.str());
362+
361363
if ((IF->getFileType() == FileType::MachO_DynamicLibrary) ||
362364
(IF->getFileType() == FileType::MachO_DynamicLibrary_Stub)) {
363365
OriginalNames[NormalizedPath.c_str()] = IF->getPath();
364366

365367
// Don't add this MachO dynamic library because we already have a
366368
// text-based stub recorded for this path.
367-
if (Dylibs.count(NormalizedPath.c_str()))
369+
if (!Inserted)
368370
continue;
369371
}
370372

371-
Dylibs[NormalizedPath.c_str()] = std::move(IF);
373+
It->second = std::move(IF);
372374
}
373375

374376
for (auto &Lib : Dylibs) {

0 commit comments

Comments
 (0)