Skip to content

Commit 41b54df

Browse files
committed
issue doxygen#11205 Building docs for the llvm-project with doxygen takes more than 20 hours
1 parent 6a86d20 commit 41b54df

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/symbolresolver.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <unordered_map>
1717
#include <string>
1818
#include <vector>
19+
#include <cassert>
1920

2021
#include "symbolresolver.h"
2122
#include "util.h"
@@ -37,6 +38,9 @@
3738
static std::mutex g_cacheMutex;
3839
static std::recursive_mutex g_cacheTypedefMutex;
3940

41+
static std::mutex g_substMapMutex;
42+
static std::unordered_map<std::string, std::pair<QCString,const MemberDef *> > g_substMap;
43+
4044
//--------------------------------------------------------------------------------------
4145

4246
/** Helper class representing the stack of items considered while resolving
@@ -1154,6 +1158,7 @@ const Definition *SymbolResolver::Private::followPath(VisitedKeys &visitedKeys,
11541158
{
11551159
AUTO_TRACE("start={},path={}",start?start->name():QCString(), path);
11561160
int is=0,ps=0,l=0;
1161+
11571162
const Definition *current=start;
11581163
// for each part of the explicit scope
11591164
while ((is=getScopeFragment(path,ps,&l))!=-1)
@@ -1240,6 +1245,7 @@ const Definition *SymbolResolver::Private::followPath(VisitedKeys &visitedKeys,
12401245
}
12411246
ps=is+l;
12421247
}
1248+
12431249
AUTO_TRACE_EXIT("result={}",current?current->name():QCString());
12441250
return current; // path could be followed
12451251
}
@@ -1497,6 +1503,24 @@ QCString SymbolResolver::Private::substTypedef(
14971503
MemberDef *bestMatch=nullptr;
14981504
int minDistance=10000; // init at "infinite"
14991505

1506+
std::string key;
1507+
const int maxAddrSize = 20;
1508+
char ptr_str[maxAddrSize];
1509+
int num = qsnprintf(ptr_str,maxAddrSize,"%p:",(void *)scope);
1510+
assert(num>0);
1511+
key.reserve(num+name.length()+1);
1512+
key+=ptr_str;
1513+
key+=name.str();
1514+
{
1515+
std::lock_guard lock(g_substMapMutex);
1516+
auto it = g_substMap.find(key);
1517+
if (it!=g_substMap.end())
1518+
{
1519+
if (pTypeDef) *pTypeDef = it->second.second;
1520+
return it->second.first;
1521+
}
1522+
}
1523+
15001524
for (Definition *d : range)
15011525
{
15021526
// only look at members
@@ -1526,6 +1550,13 @@ QCString SymbolResolver::Private::substTypedef(
15261550
if (pTypeDef) *pTypeDef=bestMatch;
15271551
}
15281552

1553+
// cache the result of the computation to give a faster answers next time, especially relevant
1554+
// if `range` has many arguments (i.e. there are many symbols with the same name in different contexts)
1555+
{
1556+
std::lock_guard lock(g_substMapMutex);
1557+
g_substMap.emplace(key,std::make_pair(result,bestMatch));
1558+
}
1559+
15291560
AUTO_TRACE_EXIT("result={}",result);
15301561
return result;
15311562
}

0 commit comments

Comments
 (0)