From e44ebd5f9b5eed18697dabbc4c1f570f60ded39c Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Thu, 10 Nov 2011 22:54:44 +0100 Subject: automoc: another runtime optimization before doing the full regexp, try a simple strstr(), if this already fails, no need to do the regexp matching. Alex --- Source/cmQtAutomoc.cxx | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx index 343d51c..3d92a59 100644 --- a/Source/cmQtAutomoc.cxx +++ b/Source/cmQtAutomoc.cxx @@ -17,11 +17,26 @@ #include "cmSourceFile.h" #include "cmSystemTools.h" -# include +#include + +#include #include "cmQtAutomoc.h" +static bool containsQ_OBJECT(const std::string& text) +{ + // this simple check is much much faster than the regexp + if (strstr(text.c_str(), "Q_OBJECT") == NULL) + { + return false; + } + + cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); + return qObjectRegExp.find(text); +} + + cmQtAutomoc::cmQtAutomoc() :Verbose(cmsys::SystemTools::GetEnv("VERBOSE") != 0) ,ColorOutput(true) @@ -527,7 +542,11 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename, std::string ownMocHeaderFile; std::string::size_type matchOffset = 0; - if (mocIncludeRegExp.find(contentsString)) + // first a simply string check for "moc" is *much* faster than the regexp, + // and if the string search already fails, we don't have to try the + // expensive regexp + if ((strstr(contentsString.c_str(), "moc") != NULL) + && (mocIncludeRegExp.find(contentsString))) { // for every moc include in the file do @@ -635,8 +654,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename, // But warn, since this is not how it is supposed to be used. if ((dotMocIncluded == false) && (mocUnderscoreIncluded == true)) { - cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); - if (qObjectRegExp.find(contentsString)) + if (containsQ_OBJECT(contentsString)) { std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " << "contains a Q_OBJECT macro, but does not include " @@ -683,7 +701,6 @@ void cmQtAutomoc::ParseHeaders(const std::set& absHeaders, const std::map& includedMocs, std::map& notIncludedMocs) { - cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); for(std::set::const_iterator hIt=absHeaders.begin(); hIt!=absHeaders.end(); ++hIt) @@ -702,7 +719,7 @@ void cmQtAutomoc::ParseHeaders(const std::set& absHeaders, const std::string currentMoc = "moc_" + basename + ".cpp"; const std::string contents = this->ReadAll(headerName); - if (qObjectRegExp.find(contents)) + if (containsQ_OBJECT(contents)) { //std::cout << "header contains Q_OBJECT macro"; notIncludedMocs[headerName] = currentMoc; -- cgit v0.12