[clang] 2fee5ef - [ByteCode] Avoid repeated hash lookups (NFC) (#126379)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 8 11:35:47 PST 2025
Author: Kazu Hirata
Date: 2025-02-08T11:35:45-08:00
New Revision: 2fee5ef2356b514dda30e89f39125a390c0d928e
URL: https://github.com/llvm/llvm-project/commit/2fee5ef2356b514dda30e89f39125a390c0d928e
DIFF: https://github.com/llvm/llvm-project/commit/2fee5ef2356b514dda30e89f39125a390c0d928e.diff
LOG: [ByteCode] Avoid repeated hash lookups (NFC) (#126379)
Added:
Modified:
clang/lib/AST/ByteCode/Program.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp
index e0b86d46428a26..833c9ef88d770f 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -18,14 +18,12 @@ using namespace clang;
using namespace clang::interp;
unsigned Program::getOrCreateNativePointer(const void *Ptr) {
- auto It = NativePointerIndices.find(Ptr);
- if (It != NativePointerIndices.end())
- return It->second;
+ auto [It, Inserted] =
+ NativePointerIndices.try_emplace(Ptr, NativePointers.size());
+ if (Inserted)
+ NativePointers.push_back(Ptr);
- unsigned Idx = NativePointers.size();
- NativePointers.push_back(Ptr);
- NativePointerIndices[Ptr] = Idx;
- return Idx;
+ return It->second;
}
const void *Program::getNativePointer(unsigned Idx) {
More information about the cfe-commits
mailing list