Skip to content

Commit

Permalink
Refactoring: modernize g_extLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Jan 22, 2021
1 parent 78569cb commit 81ce4ec
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5452,7 +5452,7 @@ void stringToSearchIndex(const QCString &docBaseUrl,const QCString &title,

//--------------------------------------------------------------------------

static QDict<int> g_extLookup;
static std::unordered_map<std::string,int> g_extLookup;

static struct Lang2ExtMap
{
Expand Down Expand Up @@ -5500,12 +5500,13 @@ bool updateLanguageMapping(const QCString &extension,const QCString &language)
QCString extName = extension.lower();
if (extName.isEmpty()) return FALSE;
if (extName.at(0)!='.') extName.prepend(".");
if (g_extLookup.find(extension)!=0) // language was already register for this ext
auto it = g_extLookup.find(extension.str());
if (it!=g_extLookup.end())
{
g_extLookup.remove(extension);
g_extLookup.erase(it); // language was already register for this ext
}
//printf("registering extension %s\n",extName.data());
g_extLookup.insert(extName,new int(parserId));
g_extLookup.insert(std::make_pair(extName,parserId));
if (!Doxygen::parserManager->registerExtension(extName,p->parserName))
{
err("Failed to assign extension %s to parser %s for language %s\n",
Expand All @@ -5522,7 +5523,6 @@ bool updateLanguageMapping(const QCString &extension,const QCString &language)
void initDefaultExtensionMapping()
{
// NOTE: when adding an extension, also add the extension in config.xml
g_extLookup.setAutoDelete(TRUE);
// extension parser id
updateLanguageMapping(".dox", "c");
updateLanguageMapping(".txt", "c"); // see bug 760836
Expand Down Expand Up @@ -5593,12 +5593,12 @@ SrcLangExt getLanguageFromFileName(const QCString& fileName)
QCString extName = fi.extension(FALSE).lower().data();
if (extName.isEmpty()) extName=".no_extension";
if (extName.at(0)!='.') extName.prepend(".");
int *pVal=g_extLookup.find(extName.data());
if (pVal) // listed extension
{
//printf("getLanguageFromFileName(%s)=%x\n",fi.extension().data(),*pVal);
return (SrcLangExt)*pVal;
}
auto it = g_extLookup.find(extName.str());
if (it!=g_extLookup.end()) // listed extension
{
//printf("getLanguageFromFileName(%s)=%x\n",fi.extension().data(),*pVal);
return (SrcLangExt)it->second;
}
//printf("getLanguageFromFileName(%s) not found!\n",fileName.data());
return SrcLangExt_Cpp; // not listed => assume C-ish language.
}
Expand Down

0 comments on commit 81ce4ec

Please sign in to comment.