Bug 1501903 - Cache the results of inThirdPartyPath. r=andi

The function is called a lot for the same paths and is rather costly, so
cache the results for each path.

Depends on D9758

Differential Revision: https://phabricator.services.mozilla.com/D9759

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Hommey 2018-10-25 21:21:36 +00:00
Родитель 371b282c0f
Коммит 3dabb0f250
2 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -23,3 +23,5 @@ public:
static FrontendPluginRegistry::Add<MozCheckAction> X("moz-check", static FrontendPluginRegistry::Add<MozCheckAction> X("moz-check",
"check moz action"); "check moz action");
DenseMap<unsigned, bool> InThirdPartyPathCache;

Просмотреть файл

@ -345,9 +345,17 @@ inline bool isPlacementNew(const CXXNewExpr *Expression) {
return true; return true;
} }
extern DenseMap<unsigned, bool> InThirdPartyPathCache;
inline bool inThirdPartyPath(SourceLocation Loc, const SourceManager &SM) { inline bool inThirdPartyPath(SourceLocation Loc, const SourceManager &SM) {
Loc = SM.getFileLoc(Loc); Loc = SM.getFileLoc(Loc);
unsigned id = SM.getFileID(Loc).getHashValue();
auto pair = InThirdPartyPathCache.find(id);
if (pair != InThirdPartyPathCache.end()) {
return pair->second;
}
SmallString<1024> RawFileName = SM.getFilename(Loc); SmallString<1024> RawFileName = SM.getFilename(Loc);
llvm::sys::fs::make_absolute(RawFileName); llvm::sys::fs::make_absolute(RawFileName);
SmallString<1024> FileName; SmallString<1024> FileName;
@ -374,11 +382,13 @@ inline bool inThirdPartyPath(SourceLocation Loc, const SourceManager &SM) {
// We found a match! // We found a match!
if (IThirdPartyB == ThirdPartyE) { if (IThirdPartyB == ThirdPartyE) {
InThirdPartyPathCache.insert(std::make_pair(id, true));
return true; return true;
} }
} }
} }
InThirdPartyPathCache.insert(std::make_pair(id, false));
return false; return false;
} }