doxygenXmlParser: pre-construct and compile constant regular expressions

and pre-construct constant strings and names

Speeds-up parsing of DTAGS so that lookup of a name takes ~1s

Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=982
This commit is contained in:
Henry Weller
2016-02-03 16:28:00 +00:00
parent 605f72a27c
commit b2d5ff67b0

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -26,7 +26,6 @@ License
#include "doxygenXmlParser.H" #include "doxygenXmlParser.H"
#include "wordRe.H" #include "wordRe.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::doxygenXmlParser::doxygenXmlParser Foam::doxygenXmlParser::doxygenXmlParser
@ -39,20 +38,32 @@ Foam::doxygenXmlParser::doxygenXmlParser
: :
dictionary(dictionary::null) dictionary(dictionary::null)
{ {
// Pre-construct and compile regular expressions
const wordRe nameRe(".*.H", wordRe::DETECT);
const wordRe searchStrRe(searchStr, wordRe::DETECT);
// Pre-construct constant strings and names to speed-up comparisons
const string slashStartTag('/' + startTag);
const string kindFileStr("kind=\"file\"");
const word compoundWord("compound");
const word nameWord("name");
const word pathWord("path");
const word filenameWord("filename");
IFstream is(fName); IFstream is(fName);
char c; // Skip forward to entry name
// skip forward to entry name
skipForward(is, startTag); skipForward(is, startTag);
char c;
while (is.get(c)) while (is.get(c))
{ {
if (c == '<') if (c == '<')
{ {
// if in block, read block name // If in block, read block name
string blockName = ""; string blockName;
string params = ""; string params;
bool readingParam = false; bool readingParam = false;
while (is.get(c) && c != '>') while (is.get(c) && c != '>')
{ {
@ -73,17 +84,17 @@ Foam::doxygenXmlParser::doxygenXmlParser
} }
} }
if (blockName == '/' + startTag) if (blockName == slashStartTag)
{ {
break; break;
} }
if ((blockName == "compound") && (params == "kind=\"file\"")) if ((blockName == compoundWord) && (params == kindFileStr))
{ {
// keep entry // Keep entry
word name = ""; word name;
fileName path = ""; fileName path;
word fName = ""; word fName;
bool foundName = false; bool foundName = false;
bool foundPath = false; bool foundPath = false;
bool foundFName = false; bool foundFName = false;
@ -92,35 +103,35 @@ Foam::doxygenXmlParser::doxygenXmlParser
{ {
word entryName; word entryName;
getEntry<word>(is, entryName); getEntry<word>(is, entryName);
if (entryName == "name") if (entryName == nameWord)
{ {
getValue<word>(is, name); getValue<word>(is, name);
if (wordRe(".*.H", wordRe::DETECT).match(name)) if (nameRe.match(name))
{ {
foundName = true; foundName = true;
} }
else else
{ {
// not interested in this compound // Not interested in this compound
break; break;
} }
} }
else if (entryName == "path") else if (entryName == pathWord)
{ {
getValue<fileName>(is, path); getValue<fileName>(is, path);
// filter path on regExp // Filter path on regExp
if (wordRe(searchStr, wordRe::DETECT).match(path)) if (searchStrRe.match(path))
{ {
foundPath = true; foundPath = true;
} }
else else
{ {
// not interested in this compound // Not interested in this compound
break; break;
} }
} }
else if (entryName == "filename") else if (entryName == filenameWord)
{ {
getValue<word>(is, fName); getValue<word>(is, fName);
foundFName = true; foundFName = true;
@ -135,7 +146,7 @@ Foam::doxygenXmlParser::doxygenXmlParser
{ {
word tName(path.components().last()); word tName(path.components().last());
// only insert if type is not already known // Only insert if type is not already known
// NOTE: not ideal for cases where there are multiple types // NOTE: not ideal for cases where there are multiple types
// but contained within different namespaces // but contained within different namespaces
// preferentially take exact match if it exists // preferentially take exact match if it exists
@ -162,7 +173,7 @@ Foam::doxygenXmlParser::doxygenXmlParser
} }
} }
// skip remanining entries // Skip remanining entries
skipBlock(is, blockName); skipBlock(is, blockName);
} }
else else
@ -182,17 +193,17 @@ void Foam::doxygenXmlParser::skipBlock
const word& blockName const word& blockName
) const ) const
{ {
// recurse to move forward in 'is' until come across </blockName> // Recurse to move forward in 'is' until come across </blockName>
string closeName = ""; string closeName;
char c; char c;
while (is.good() && (closeName != blockName)) while (is.good() && (closeName != blockName))
{ {
// fast-forward until we reach a '<' // Fast-forward until we reach a '<'
while (is.get(c) && c != '<') while (is.get(c) && c != '<')
{} {}
// check to see if this is a closing block // Check to see if this is a closing block
if (is.get(c) && c == '/') if (is.get(c) && c == '/')
{ {
closeName = ""; closeName = "";
@ -212,7 +223,7 @@ void Foam::doxygenXmlParser::skipForward
const word& blockName const word& blockName
) const ) const
{ {
// recurse to move forward in 'is' until come across <blockName> // Recurse to move forward in 'is' until come across <blockName>
string entryName = ""; string entryName = "";
char c; char c;
@ -220,7 +231,7 @@ void Foam::doxygenXmlParser::skipForward
{ {
entryName = ""; entryName = "";
// fast-forward until we reach a '<' // Fast-forward until we reach a '<'
while (is.get(c) && c != '<') while (is.get(c) && c != '<')
{} {}
@ -233,4 +244,3 @@ void Foam::doxygenXmlParser::skipForward
// ************************************************************************* // // ************************************************************************* //