Minor optimisations to the preprocessor

This commit is contained in:
Raphael Geissert 2011-01-30 18:47:49 -06:00
parent b4a249f26e
commit 29ca5fbe1e
1 changed files with 8 additions and 0 deletions

View File

@ -713,6 +713,9 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe
// Get the DEF in this line: "#ifdef DEF"
std::string Preprocessor::getdef(std::string line, bool def)
{
if (line.empty() || line[0] != '#')
return "";
// If def is true, the line must start with "#ifdef"
if (def && line.compare(0, 7, "#ifdef ") != 0 && line.compare(0, 4, "#if ") != 0
&& (line.compare(0, 6, "#elif ") != 0 || line.compare(0, 7, "#elif !") == 0))
@ -787,6 +790,8 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
if (_errorLogger)
_errorLogger->reportProgress(filename, "Preprocessing (get configurations 1)", 0);
if (line.empty())
continue;
if (line.compare(0, 6, "#file ") == 0)
{
@ -818,6 +823,9 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
if (!line.empty() && line.compare(0, 3, "#if") != 0)
includeguard = false;
if (line[0] != '#')
continue;
if (includeguard)
continue;