Skip to content

Commit

Permalink
Refactoring: move from Dispatcher back to inheritance for IndexIntf
Browse files Browse the repository at this point in the history
Rationale: is complex, hard to debug, and no clear performance benefits.
  • Loading branch information
doxygen committed Apr 28, 2024
1 parent d42f002 commit 3730405
Show file tree
Hide file tree
Showing 30 changed files with 178 additions and 163 deletions.
8 changes: 4 additions & 4 deletions src/clangparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,11 @@ void ClangTUParser::writeLineNumber(OutputCodeList &ol,const FileDef *fd,uint32_
}

// set search page target
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
QCString lineAnchor;
lineAnchor.sprintf("l%05d",line);
Doxygen::searchIndex->setCurrentDoc(fd,lineAnchor,TRUE);
Doxygen::searchIndex.setCurrentDoc(fd,lineAnchor,TRUE);
}

//printf("writeLineNumber(%d) g_searchForBody=%d\n",line,g_searchForBody);
Expand Down Expand Up @@ -882,9 +882,9 @@ void ClangTUParser::writeSources(OutputCodeList &ol,const FileDef *fd)
)
{
linkIdentifier(ol,fd,line,column,s,i);
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
Doxygen::searchIndex->addWord(s,FALSE);
Doxygen::searchIndex.addWord(s,FALSE);
}
}
else
Expand Down
10 changes: 5 additions & 5 deletions src/code.l
Original file line number Diff line number Diff line change
Expand Up @@ -2373,24 +2373,24 @@ static void popScope(yyscan_t yyscanner)
static void setCurrentDoc(yyscan_t yyscanner,const QCString &anchor)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
if (yyextra->searchCtx)
{
Doxygen::searchIndex->setCurrentDoc(yyextra->searchCtx,yyextra->searchCtx->anchor(),FALSE);
Doxygen::searchIndex.setCurrentDoc(yyextra->searchCtx,yyextra->searchCtx->anchor(),FALSE);
}
else
{
Doxygen::searchIndex->setCurrentDoc(yyextra->sourceFileDef,anchor,TRUE);
Doxygen::searchIndex.setCurrentDoc(yyextra->sourceFileDef,anchor,TRUE);
}
}
}
static void addToSearchIndex(yyscan_t /*yyscanner*/,const QCString &text)
{
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
Doxygen::searchIndex->addWord(text,FALSE);
Doxygen::searchIndex.addWord(text,FALSE);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/docnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ DocWord::DocWord(DocParser *parser,DocNodeVariant *parent,const QCString &word)
DocNode(parser,parent), m_word(word)
{
//printf("new word %s url=%s\n",qPrint(word),qPrint(parser->context.searchUrl));
if (Doxygen::searchIndex && !parser->context.searchUrl.isEmpty())
if (Doxygen::searchIndex.enabled() && !parser->context.searchUrl.isEmpty())
{
Doxygen::searchIndex->addWord(word,false);
Doxygen::searchIndex.addWord(word,false);
}
}

Expand All @@ -195,9 +195,9 @@ DocLinkedWord::DocLinkedWord(DocParser *parser,DocNodeVariant *parent,const QCSt
{
//printf("DocLinkedWord: new word %s url=%s tooltip='%s'\n",
// qPrint(word),qPrint(parser->context.searchUrl),qPrint(tooltip));
if (Doxygen::searchIndex && !parser->context.searchUrl.isEmpty())
if (Doxygen::searchIndex.enabled() && !parser->context.searchUrl.isEmpty())
{
Doxygen::searchIndex->addWord(word,false);
Doxygen::searchIndex.addWord(word,false);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/docparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1971,17 +1971,17 @@ IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf,
}
parser->context.scope = ctx;

if (indexWords && Doxygen::searchIndex)
if (indexWords && Doxygen::searchIndex.enabled())
{
if (md)
{
parser->context.searchUrl=md->getOutputFileBase();
Doxygen::searchIndex->setCurrentDoc(md,md->anchor(),false);
Doxygen::searchIndex.setCurrentDoc(md,md->anchor(),false);
}
else if (ctx)
{
parser->context.searchUrl=ctx->getOutputFileBase();
Doxygen::searchIndex->setCurrentDoc(ctx,ctx->anchor(),false);
Doxygen::searchIndex.setCurrentDoc(ctx,ctx->anchor(),false);
}
}
else
Expand Down
1 change: 0 additions & 1 deletion src/docsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ struct DocSets::Private

DocSets::DocSets() : p(std::make_unique<Private>()) {}
DocSets::~DocSets() = default;
DEFAULT_MOVABLE_IMPL(DocSets)

void DocSets::initialize()
{
Expand Down
6 changes: 3 additions & 3 deletions src/docsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <memory>

#include "indexlist.h"
#include "qcstring.h"
#include "construct.h"

Expand All @@ -31,13 +32,12 @@ class MemberDef;
* These files can be used to create context help
* for use within Apple's Xcode 3.0 development environment
*/
class DocSets
class DocSets : public IndexIntf
{

public:
DocSets();
~DocSets();
ONLY_MOVABLE_DECL(DocSets)
NON_COPYABLE(DocSets)

void initialize();
void finalize();
Expand Down
51 changes: 25 additions & 26 deletions src/doxygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
#include "pagedef.h"
#include "commentcnv.h"
#include "cmdmapper.h"
#include "searchindex.h"
#include "searchindex_js.h"
#include "parserintf.h"
#include "htags.h"
Expand Down Expand Up @@ -152,7 +151,7 @@ std::unique_ptr<PageDef> Doxygen::mainPage;
std::unique_ptr<NamespaceDef> Doxygen::globalNamespaceDef;
NamespaceDefMutable *Doxygen::globalScope;
bool Doxygen::parseSourcesNeeded = FALSE;
std::unique_ptr<SearchIndexIntf> Doxygen::searchIndex;
SearchIndexIntf Doxygen::searchIndex;
SymbolMap<Definition>*Doxygen::symbolMap;
ClangUsrMap *Doxygen::clangUsrMap = nullptr;
Cache<std::string,LookupInfo> *Doxygen::typeLookupCache;
Expand Down Expand Up @@ -7607,10 +7606,10 @@ static void addToIndices()
if (cd->isLinkableInProject())
{
Doxygen::indexList->addIndexItem(cd.get(),nullptr);
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
Doxygen::searchIndex->setCurrentDoc(cd.get(),cd->anchor(),FALSE);
Doxygen::searchIndex->addWord(cd->localName(),TRUE);
Doxygen::searchIndex.setCurrentDoc(cd.get(),cd->anchor(),FALSE);
Doxygen::searchIndex.addWord(cd->localName(),TRUE);
}
}
}
Expand All @@ -7620,10 +7619,10 @@ static void addToIndices()
if (cd->isLinkableInProject())
{
Doxygen::indexList->addIndexItem(cd.get(),nullptr);
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
Doxygen::searchIndex->setCurrentDoc(cd.get(),cd->anchor(),FALSE);
Doxygen::searchIndex->addWord(cd->localName(),TRUE);
Doxygen::searchIndex.setCurrentDoc(cd.get(),cd->anchor(),FALSE);
Doxygen::searchIndex.addWord(cd->localName(),TRUE);
}
}
}
Expand All @@ -7633,10 +7632,10 @@ static void addToIndices()
if (nd->isLinkableInProject())
{
Doxygen::indexList->addIndexItem(nd.get(),nullptr);
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
Doxygen::searchIndex->setCurrentDoc(nd.get(),nd->anchor(),FALSE);
Doxygen::searchIndex->addWord(nd->localName(),TRUE);
Doxygen::searchIndex.setCurrentDoc(nd.get(),nd->anchor(),FALSE);
Doxygen::searchIndex.addWord(nd->localName(),TRUE);
}
}
}
Expand All @@ -7645,20 +7644,20 @@ static void addToIndices()
{
for (const auto &fd : *fn)
{
if (Doxygen::searchIndex && fd->isLinkableInProject())
if (Doxygen::searchIndex.enabled() && fd->isLinkableInProject())
{
Doxygen::searchIndex->setCurrentDoc(fd.get(),fd->anchor(),FALSE);
Doxygen::searchIndex->addWord(fd->localName(),TRUE);
Doxygen::searchIndex.setCurrentDoc(fd.get(),fd->anchor(),FALSE);
Doxygen::searchIndex.addWord(fd->localName(),TRUE);
}
}
}

auto addWordsForTitle = [](const Definition *d,const QCString &anchor,const QCString &title)
{
Doxygen::indexList->addIndexItem(d,nullptr,QCString(),filterTitle(title));
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
Doxygen::searchIndex->setCurrentDoc(d,anchor,false);
Doxygen::searchIndex.setCurrentDoc(d,anchor,false);
std::string s = title.str();
static const reg::Ex re(R"(\a[\w-]*)");
reg::Iterator it(s,re);
Expand All @@ -7667,7 +7666,7 @@ static void addToIndices()
{
const auto &match = *it;
std::string matchStr = match.str();
Doxygen::searchIndex->addWord(matchStr.c_str(),true);
Doxygen::searchIndex.addWord(matchStr.c_str(),true);
}
}
};
Expand Down Expand Up @@ -7695,22 +7694,22 @@ static void addToIndices()

auto addMemberToSearchIndex = [](const MemberDef *md)
{
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
Doxygen::searchIndex->setCurrentDoc(md,md->anchor(),FALSE);
Doxygen::searchIndex.setCurrentDoc(md,md->anchor(),FALSE);
QCString ln=md->localName();
QCString qn=md->qualifiedName();
Doxygen::searchIndex->addWord(ln,TRUE);
Doxygen::searchIndex.addWord(ln,TRUE);
if (ln!=qn)
{
Doxygen::searchIndex->addWord(qn,TRUE);
Doxygen::searchIndex.addWord(qn,TRUE);
if (md->getClassDef())
{
Doxygen::searchIndex->addWord(md->getClassDef()->displayName(),TRUE);
Doxygen::searchIndex.addWord(md->getClassDef()->displayName(),TRUE);
}
if (md->getNamespaceDef())
{
Doxygen::searchIndex->addWord(md->getNamespaceDef()->displayName(),TRUE);
Doxygen::searchIndex.addWord(md->getNamespaceDef()->displayName(),TRUE);
}
}
}
Expand Down Expand Up @@ -12643,10 +12642,10 @@ void generateOutput()
if (generateHtml && searchEngine && serverBasedSearch)
{
g_s.begin("Generating search index\n");
if (Doxygen::searchIndex->kind()==SearchIndexIntf::Internal) // write own search index
if (Doxygen::searchIndex.kind()==SearchIndexIntf::Internal) // write own search index
{
HtmlGenerator::writeSearchPage();
Doxygen::searchIndex->write(Config_getString(HTML_OUTPUT)+"/search/search.idx");
Doxygen::searchIndex.write(Config_getString(HTML_OUTPUT)+"/search/search.idx");
}
else // write data for external search index
{
Expand All @@ -12660,7 +12659,7 @@ void generateOutput()
{
searchDataFile.prepend(Config_getString(OUTPUT_DIRECTORY)+"/");
}
Doxygen::searchIndex->write(searchDataFile);
Doxygen::searchIndex.write(searchDataFile);
}
g_s.end();
}
Expand Down
4 changes: 2 additions & 2 deletions src/doxygen.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
#include "define.h"
#include "cache.h"
#include "symbolmap.h"
#include "searchindex.h"

#define THREAD_LOCAL thread_local
#define AtomicInt std::atomic_int

class RefList;
class PageLinkedMap;
class PageDef;
class SearchIndexIntf;
class ParserManager;
class BufStr;
class MemberDef;
Expand Down Expand Up @@ -111,7 +111,7 @@ class Doxygen
static NamespaceDefMutable *globalScope;
static QCString htmlFileExtension;
static bool parseSourcesNeeded;
static std::unique_ptr<SearchIndexIntf> searchIndex;
static SearchIndexIntf searchIndex;
static SymbolMap<Definition> *symbolMap;
static ClangUsrMap *clangUsrMap;
static Cache<std::string,LookupInfo> *typeLookupCache;
Expand Down
1 change: 0 additions & 1 deletion src/eclipsehelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ struct EclipseHelp::Private

EclipseHelp::EclipseHelp() : p(std::make_unique<Private>()) {}
EclipseHelp::~EclipseHelp() = default;
DEFAULT_MOVABLE_IMPL(EclipseHelp)

/*!
* \brief Initialize the Eclipse generator
Expand Down
5 changes: 3 additions & 2 deletions src/eclipsehelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "qcstring.h"
#include "construct.h"
#include "indexlist.h"

/* -- forward declarations */
class Definition;
Expand All @@ -39,12 +40,12 @@ class MemberDef;
* These files can be used to generate a help plugin readable
* by the Eclipse IDE.
*/
class EclipseHelp
class EclipseHelp : public IndexIntf
{
public:
EclipseHelp();
virtual ~EclipseHelp();
ONLY_MOVABLE_DECL(EclipseHelp)
NON_COPYABLE(EclipseHelp)

/* -- index interface */
virtual void initialize();
Expand Down
10 changes: 5 additions & 5 deletions src/fortrancode.l
Original file line number Diff line number Diff line change
Expand Up @@ -887,24 +887,24 @@ static void startFontClass(yyscan_t yyscanner,const char *s)
static void setCurrentDoc(yyscan_t yyscanner,const QCString &anchor)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
if (yyextra->searchCtx)
{
Doxygen::searchIndex->setCurrentDoc(yyextra->searchCtx,yyextra->searchCtx->anchor(),FALSE);
Doxygen::searchIndex.setCurrentDoc(yyextra->searchCtx,yyextra->searchCtx->anchor(),FALSE);
}
else
{
Doxygen::searchIndex->setCurrentDoc(yyextra->sourceFileDef,anchor,TRUE);
Doxygen::searchIndex.setCurrentDoc(yyextra->sourceFileDef,anchor,TRUE);
}
}
}

static void addToSearchIndex(yyscan_t /*yyscanner*/,const QCString &text)
{
if (Doxygen::searchIndex)
if (Doxygen::searchIndex.enabled())
{
Doxygen::searchIndex->addWord(text,FALSE);
Doxygen::searchIndex.addWord(text,FALSE);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/ftvhelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ struct FTVHelp::Private
*/
FTVHelp::FTVHelp(bool TLI) : p(std::make_unique<Private>(TLI)) {}
FTVHelp::~FTVHelp() = default;
DEFAULT_MOVABLE_IMPL(FTVHelp)

/*! This will create a folder tree view table of contents file (tree.js).
* \sa finalize()
Expand Down
5 changes: 3 additions & 2 deletions src/ftvhelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <vector>
#include "qcstring.h"
#include "construct.h"
#include "indexlist.h"

class Definition;
class MemberDef;
Expand All @@ -36,12 +37,12 @@ class TextStream;

/** A class that generates a dynamic tree view side panel.
*/
class FTVHelp
class FTVHelp : public IndexIntf
{
public:
FTVHelp(bool LTI);
~FTVHelp();
ONLY_MOVABLE_DECL(FTVHelp)
NON_COPYABLE(FTVHelp)

void initialize();
void finalize();
Expand Down

0 comments on commit 3730405

Please sign in to comment.