Skip to content

Commit 2fee5ef

Browse files
[ByteCode] Avoid repeated hash lookups (NFC) (#126379)
1 parent 4510071 commit 2fee5ef

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ using namespace clang;
1818
using namespace clang::interp;
1919

2020
unsigned Program::getOrCreateNativePointer(const void *Ptr) {
21-
auto It = NativePointerIndices.find(Ptr);
22-
if (It != NativePointerIndices.end())
23-
return It->second;
21+
auto [It, Inserted] =
22+
NativePointerIndices.try_emplace(Ptr, NativePointers.size());
23+
if (Inserted)
24+
NativePointers.push_back(Ptr);
2425

25-
unsigned Idx = NativePointers.size();
26-
NativePointers.push_back(Ptr);
27-
NativePointerIndices[Ptr] = Idx;
28-
return Idx;
26+
return It->second;
2927
}
3028

3129
const void *Program::getNativePointer(unsigned Idx) {

0 commit comments

Comments
 (0)