[llvm] Add StringMap::lookup() overload to take a default value and return a reference to the value to avoid a copy (PR #115469)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 08:05:35 PST 2024


================
@@ -257,6 +257,15 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
     return ValueTy();
   }
 
+  /// lookup - Return the entry for the specified key, or a default
+  /// provided value if no such entry exists.
+  const ValueTy &lookup(StringRef Key, const ValueTy& Value) const {
----------------
kuhar wrote:

I think one safer alternative would be to return the looked up value through a pointer

https://github.com/llvm/llvm-project/pull/115469


More information about the llvm-commits mailing list