ClearMatches: Only clear matches which were actually set
ClearMatches was clearing many variables which were never set in the first place. Instead, store how many matches were made last time and only clear those. It is moved to the cmMakefile class since it is a common utility used by multiple commands.
This commit is contained in:
parent
bb1c41a085
commit
f718b30a95
|
@ -595,7 +595,7 @@ namespace
|
|||
{
|
||||
def = cmIfCommand::GetVariableOrString(*arg, makefile);
|
||||
const char* rex = (argP2)->c_str();
|
||||
cmStringCommand::ClearMatches(makefile);
|
||||
makefile->ClearMatches();
|
||||
cmsys::RegularExpression regEntry;
|
||||
if ( !regEntry.compile(rex) )
|
||||
{
|
||||
|
@ -607,7 +607,7 @@ namespace
|
|||
}
|
||||
if (regEntry.find(def))
|
||||
{
|
||||
cmStringCommand::StoreMatches(makefile, regEntry);
|
||||
makefile->StoreMatches(regEntry);
|
||||
*arg = "1";
|
||||
}
|
||||
else
|
||||
|
|
|
@ -148,6 +148,8 @@ cmMakefile::cmMakefile(): Internal(new Internals)
|
|||
this->Initialize();
|
||||
this->PreOrder = false;
|
||||
this->GeneratingBuildSystem = false;
|
||||
|
||||
this->NumLastMatches = 0;
|
||||
}
|
||||
|
||||
cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
|
||||
|
@ -196,6 +198,8 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
|
|||
this->CheckSystemVars = mf.CheckSystemVars;
|
||||
this->ListFileStack = mf.ListFileStack;
|
||||
this->OutputToSource = mf.OutputToSource;
|
||||
|
||||
this->NumLastMatches = mf.NumLastMatches;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -4328,6 +4332,42 @@ std::vector<cmSourceFile*> cmMakefile::GetQtUiFilesWithOptions() const
|
|||
return this->QtUiFilesWithOptions;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmMakefile::ClearMatches()
|
||||
{
|
||||
std::stringstream sstr;
|
||||
for (unsigned int i=0; i<this->NumLastMatches; i++)
|
||||
{
|
||||
sstr.str("");
|
||||
sstr << "CMAKE_MATCH_" << i;
|
||||
std::string const& name = sstr.str();
|
||||
std::string const& s = this->GetSafeDefinition(name);
|
||||
if(!s.empty())
|
||||
{
|
||||
this->AddDefinition(name, "");
|
||||
this->MarkVariableAsUsed(name);
|
||||
}
|
||||
}
|
||||
this->NumLastMatches = 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmMakefile::StoreMatches(cmsys::RegularExpression& re)
|
||||
{
|
||||
for (unsigned int i=0; i<10; i++)
|
||||
{
|
||||
std::string m = re.match(i);
|
||||
if(m.size() > 0)
|
||||
{
|
||||
char name[128];
|
||||
sprintf(name, "CMAKE_MATCH_%d", i);
|
||||
this->AddDefinition(name, re.match(i).c_str());
|
||||
this->MarkVariableAsUsed(name);
|
||||
this->NumLastMatches = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmPolicies::PolicyStatus
|
||||
cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id) const
|
||||
|
|
|
@ -889,6 +889,9 @@ public:
|
|||
const std::string& feature,
|
||||
std::string *error = 0) const;
|
||||
|
||||
void ClearMatches();
|
||||
void StoreMatches(cmsys::RegularExpression& re);
|
||||
|
||||
protected:
|
||||
// add link libraries and directories to the target
|
||||
void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
|
||||
|
@ -1065,6 +1068,8 @@ private:
|
|||
cmSourceFile* source);
|
||||
|
||||
std::vector<cmSourceFile*> QtUiFilesWithOptions;
|
||||
|
||||
unsigned int NumLastMatches;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -305,7 +305,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
|
|||
input += args[i];
|
||||
}
|
||||
|
||||
this->ClearMatches(this->Makefile);
|
||||
this->Makefile->ClearMatches();
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
if(!re.compile(regex.c_str()))
|
||||
|
@ -320,7 +320,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
|
|||
std::string output;
|
||||
if(re.find(input.c_str()))
|
||||
{
|
||||
this->StoreMatches(this->Makefile, re);
|
||||
this->Makefile->StoreMatches(re);
|
||||
std::string::size_type l = re.start();
|
||||
std::string::size_type r = re.end();
|
||||
if(r-l == 0)
|
||||
|
@ -354,7 +354,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
|
|||
input += args[i];
|
||||
}
|
||||
|
||||
this->ClearMatches(this->Makefile);
|
||||
this->Makefile->ClearMatches();
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
if(!re.compile(regex.c_str()))
|
||||
|
@ -371,7 +371,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
|
|||
const char* p = input.c_str();
|
||||
while(re.find(p))
|
||||
{
|
||||
this->StoreMatches(this->Makefile, re);
|
||||
this->Makefile->StoreMatches(re);
|
||||
std::string::size_type l = re.start();
|
||||
std::string::size_type r = re.end();
|
||||
if(r-l == 0)
|
||||
|
@ -458,7 +458,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
|||
input += args[i];
|
||||
}
|
||||
|
||||
this->ClearMatches(this->Makefile);
|
||||
this->Makefile->ClearMatches();
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
if(!re.compile(regex.c_str()))
|
||||
|
@ -475,7 +475,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
|||
std::string::size_type base = 0;
|
||||
while(re.find(input.c_str()+base))
|
||||
{
|
||||
this->StoreMatches(this->Makefile, re);
|
||||
this->Makefile->StoreMatches(re);
|
||||
std::string::size_type l2 = re.start();
|
||||
std::string::size_type r = re.end();
|
||||
|
||||
|
@ -535,38 +535,6 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
|||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmStringCommand::ClearMatches(cmMakefile* mf)
|
||||
{
|
||||
for (unsigned int i=0; i<10; i++)
|
||||
{
|
||||
char name[128];
|
||||
sprintf(name, "CMAKE_MATCH_%d", i);
|
||||
const char* s = mf->GetDefinition(name);
|
||||
if(s && *s != 0)
|
||||
{
|
||||
mf->AddDefinition(name, "");
|
||||
mf->MarkVariableAsUsed(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmStringCommand::StoreMatches(cmMakefile* mf,cmsys::RegularExpression& re)
|
||||
{
|
||||
for (unsigned int i=0; i<10; i++)
|
||||
{
|
||||
std::string m = re.match(i);
|
||||
if(m.size() > 0)
|
||||
{
|
||||
char name[128];
|
||||
sprintf(name, "CMAKE_MATCH_%d", i);
|
||||
mf->AddDefinition(name, re.match(i).c_str());
|
||||
mf->MarkVariableAsUsed(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool cmStringCommand::HandleFindCommand(std::vector<std::string> const&
|
||||
args)
|
||||
|
|
|
@ -53,8 +53,6 @@ public:
|
|||
virtual std::string GetName() const { return "string";}
|
||||
|
||||
cmTypeMacro(cmStringCommand, cmCommand);
|
||||
static void ClearMatches(cmMakefile* mf);
|
||||
static void StoreMatches(cmMakefile* mf, cmsys::RegularExpression& re);
|
||||
protected:
|
||||
bool HandleConfigureCommand(std::vector<std::string> const& args);
|
||||
bool HandleAsciiCommand(std::vector<std::string> const& args);
|
||||
|
|
Loading…
Reference in New Issue