48
48
#include " llvm/Support/Regex.h"
49
49
#include " llvm/Support/ScopedPrinter.h"
50
50
#include < algorithm>
51
+ #include < map>
51
52
#include < string>
52
53
#include < vector>
53
54
@@ -221,16 +222,19 @@ class QueryDriverDatabase : public GlobalCompilationDatabase {
221
222
222
223
llvm::SmallString<128 > Driver (Cmd->CommandLine .front ());
223
224
llvm::sys::fs::make_absolute (Cmd->Directory , Driver);
225
+ llvm::StringRef Ext = llvm::sys::path::extension (File).trim (' .' );
226
+ auto Key = std::make_pair (Driver.str (), Ext);
224
227
225
- llvm::ArrayRef <std::string> SystemIncludes;
228
+ std::vector <std::string> SystemIncludes;
226
229
{
227
230
std::lock_guard<std::mutex> Lock (Mu);
228
231
229
- llvm::StringRef Ext = llvm::sys::path::extension (File).trim (' .' );
230
- auto It = DriverToIncludesCache.try_emplace ({Driver, Ext});
231
- if (It.second )
232
- It.first ->second = extractSystemIncludes (Driver, Ext, QueryDriverRegex);
233
- SystemIncludes = It.first ->second ;
232
+ auto It = DriverToIncludesCache.find (Key);
233
+ if (It != DriverToIncludesCache.end ())
234
+ SystemIncludes = It->second ;
235
+ else
236
+ DriverToIncludesCache[Key] = SystemIncludes =
237
+ extractSystemIncludes (Key.first , Key.second , QueryDriverRegex);
234
238
}
235
239
236
240
return addSystemIncludes (*Cmd, SystemIncludes);
@@ -239,8 +243,8 @@ class QueryDriverDatabase : public GlobalCompilationDatabase {
239
243
private:
240
244
mutable std::mutex Mu;
241
245
// Caches includes extracted from a driver.
242
- mutable llvm::DenseMap <std::pair<StringRef, StringRef >,
243
- std::vector<std::string>>
246
+ mutable std::map <std::pair<std::string, std::string >,
247
+ std::vector<std::string>>
244
248
DriverToIncludesCache;
245
249
mutable llvm::Regex QueryDriverRegex;
246
250
0 commit comments