Also cache negative results in GetXcodeSDKPath (NFC)
authorAdrian Prantl <aprantl@apple.com>
Tue, 26 May 2020 22:40:43 +0000 (15:40 -0700)
committerAdrian Prantl <aprantl@apple.com>
Wed, 27 May 2020 19:26:04 +0000 (12:26 -0700)
This fixes a performance issue in the failure case.

rdar://63547920

Differential Revision: https://reviews.llvm.org/D80595

lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm

index 79ccc52..cb6f034 100644 (file)
@@ -367,8 +367,10 @@ llvm::StringRef HostInfoMacOSX::GetXcodeSDKPath(XcodeSDK sdk) {
   static std::mutex g_sdk_path_mutex;
 
   std::lock_guard<std::mutex> guard(g_sdk_path_mutex);
-  std::string &path = g_sdk_path[sdk.GetString()];
-  if (path.empty())
-    path = GetXcodeSDK(sdk);
+  auto it = g_sdk_path.find(sdk.GetString());
+  if (it != g_sdk_path.end())
+    return it->second;
+  std::string path = GetXcodeSDK(sdk);
+  g_sdk_path.insert({sdk.GetString(), path});
   return path;
 }