regex: Use static regexs where possible

Rather than declaring and compiling a constant regex every time a chunk
of code is executed, build the regex once.
This commit is contained in:
Ben Boeckel 2014-04-30 13:12:29 -04:00
parent 9e8fa1043c
commit 3e7194a215
5 changed files with 14 additions and 19 deletions

View File

@ -588,8 +588,8 @@ void cmCPackNSISGenerator::CreateMenuLinks( cmOStringStream& str,
return; return;
} }
cmsys::RegularExpression urlRegex; static cmsys::RegularExpression
urlRegex.compile("^(mailto:|(ftps?|https?|news)://).*$"); urlRegex("^(mailto:|(ftps?|https?|news)://).*$");
std::vector<std::string>::iterator it; std::vector<std::string>::iterator it;
for ( it = cpackMenuLinksVector.begin(); for ( it = cpackMenuLinksVector.begin();

View File

@ -1831,8 +1831,8 @@ cmComputeLinkInformation::AddLibraryRuntimeInfo(std::string const& fullPath)
{ {
if(fullPath.find(".framework") != std::string::npos) if(fullPath.find(".framework") != std::string::npos)
{ {
cmsys::RegularExpression splitFramework; static cmsys::RegularExpression
splitFramework.compile("^(.*)/(.*).framework/(.*)$"); splitFramework("^(.*)/(.*).framework/(.*)$");
if(splitFramework.find(fullPath) && if(splitFramework.find(fullPath) &&
(std::string::npos != (std::string::npos !=
splitFramework.match(3).find(splitFramework.match(2)))) splitFramework.match(3).find(splitFramework.match(2))))

View File

@ -469,12 +469,11 @@ std::string::size_type cmGeneratorExpression::Find(const std::string &input)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmGeneratorExpression::IsValidTargetName(const std::string &input) bool cmGeneratorExpression::IsValidTargetName(const std::string &input)
{ {
cmsys::RegularExpression targetNameValidator;
// The ':' is supported to allow use with IMPORTED targets. At least // The ':' is supported to allow use with IMPORTED targets. At least
// Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter. // Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter.
targetNameValidator.compile("^[A-Za-z0-9_.:+-]+$"); static cmsys::RegularExpression targetNameValidator("^[A-Za-z0-9_.:+-]+$");
return targetNameValidator.find(input.c_str()); return targetNameValidator.find(input);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -401,8 +401,7 @@ struct CompilerIdNode : public cmGeneratorExpressionNode
{ {
return compilerId ? compilerId : ""; return compilerId ? compilerId : "";
} }
cmsys::RegularExpression compilerIdValidator; static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$");
compilerIdValidator.compile("^[A-Za-z0-9_]*$");
if (!compilerIdValidator.find(parameters.begin()->c_str())) if (!compilerIdValidator.find(parameters.begin()->c_str()))
{ {
reportError(context, content->GetOriginalExpression(), reportError(context, content->GetOriginalExpression(),
@ -509,8 +508,7 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode
return compilerVersion ? compilerVersion : ""; return compilerVersion ? compilerVersion : "";
} }
cmsys::RegularExpression compilerIdValidator; static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$");
compilerIdValidator.compile("^[0-9\\.]*$");
if (!compilerIdValidator.find(parameters.begin()->c_str())) if (!compilerIdValidator.find(parameters.begin()->c_str()))
{ {
reportError(context, content->GetOriginalExpression(), reportError(context, content->GetOriginalExpression(),
@ -711,8 +709,7 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
{ {
return configurationNode.Evaluate(parameters, context, content, 0); return configurationNode.Evaluate(parameters, context, content, 0);
} }
cmsys::RegularExpression configValidator; static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$");
configValidator.compile("^[A-Za-z0-9_]*$");
if (!configValidator.find(parameters.begin()->c_str())) if (!configValidator.find(parameters.begin()->c_str()))
{ {
reportError(context, content->GetOriginalExpression(), reportError(context, content->GetOriginalExpression(),
@ -884,8 +881,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
"$<TARGET_PROPERTY:...> expression requires one or two parameters"); "$<TARGET_PROPERTY:...> expression requires one or two parameters");
return std::string(); return std::string();
} }
cmsys::RegularExpression propertyNameValidator; static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
propertyNameValidator.compile("^[A-Za-z0-9_]+$");
cmTarget const* target = context->HeadTarget; cmTarget const* target = context->HeadTarget;
std::string propertyName = *parameters.begin(); std::string propertyName = *parameters.begin();

View File

@ -39,8 +39,8 @@ public:
if(file.rfind(".framework") != std::string::npos) if(file.rfind(".framework") != std::string::npos)
{ {
cmsys::RegularExpression splitFramework; static cmsys::RegularExpression
splitFramework.compile("^(.*)/(.*).framework/(.*)$"); splitFramework("^(.*)/(.*).framework/(.*)$");
if(splitFramework.find(file) && if(splitFramework.find(file) &&
(std::string::npos != (std::string::npos !=
splitFramework.match(3).find(splitFramework.match(2)))) splitFramework.match(3).find(splitFramework.match(2))))
@ -326,8 +326,8 @@ void cmOrderDirectories::AddRuntimeLibrary(std::string const& fullPath,
if(fullPath.rfind(".framework") != std::string::npos) if(fullPath.rfind(".framework") != std::string::npos)
{ {
cmsys::RegularExpression splitFramework; static cmsys::RegularExpression
splitFramework.compile("^(.*)/(.*).framework/(.*)$"); splitFramework("^(.*)/(.*).framework/(.*)$");
if(splitFramework.find(fullPath) && if(splitFramework.find(fullPath) &&
(std::string::npos != (std::string::npos !=
splitFramework.match(3).find(splitFramework.match(2)))) splitFramework.match(3).find(splitFramework.match(2))))