summaryrefslogtreecommitdiffstats
path: root/Source/cmQtAutomoc.cxx
diff options
context:
space:
mode:
authorAlex Neundorf <neundorf@kde.org>2011-11-10 21:54:44 (GMT)
committerAlex Neundorf <neundorf@kde.org>2011-11-10 21:54:44 (GMT)
commite44ebd5f9b5eed18697dabbc4c1f570f60ded39c (patch)
tree5e81e78ec433e122d09118cad77c21bfe3373ba9 /Source/cmQtAutomoc.cxx
parent142317782842751dba4e68f016f3c89c692dc5ac (diff)
downloadCMake-e44ebd5f9b5eed18697dabbc4c1f570f60ded39c.zip
CMake-e44ebd5f9b5eed18697dabbc4c1f570f60ded39c.tar.gz
CMake-e44ebd5f9b5eed18697dabbc4c1f570f60ded39c.tar.bz2
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
Diffstat (limited to 'Source/cmQtAutomoc.cxx')
-rw-r--r--Source/cmQtAutomoc.cxx29
1 files 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 <cmsys/Terminal.h>
+#include <cmsys/Terminal.h>
+
+#include <string.h>
#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<std::string>& absHeaders,
const std::map<std::string, std::string>& includedMocs,
std::map<std::string, std::string>& notIncludedMocs)
{
- cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]");
for(std::set<std::string>::const_iterator hIt=absHeaders.begin();
hIt!=absHeaders.end();
++hIt)
@@ -702,7 +719,7 @@ void cmQtAutomoc::ParseHeaders(const std::set<std::string>& 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;