[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [clazy] src: Minor optimization: Use a member variable instead of virtual function
From:       Sergio Martins <null () kde ! org>
Date:       2017-05-01 1:28:35
Message-ID: E1d508h-0006jE-QS () code ! kde ! org
[Download RAW message or body]

Git commit 76e9eab45292409c5937ada0fba3b8dcc1b5f877 by Sergio Martins.
Committed on 01/05/2017 at 01:25.
Pushed by smartins into branch 'master'.

Minor optimization: Use a member variable instead of virtual function

That method is called a lot.

M  +2    -2    src/Clazy.cpp
M  +2    -1    src/checkbase.cpp
M  +10   -2    src/checkbase.h
M  +1    -1    src/checks/level2/missing-type-info.cpp
M  +0    -1    src/checks/level2/missing-type-info.h

https://commits.kde.org/clazy/76e9eab45292409c5937ada0fba3b8dcc1b5f877

diff --git a/src/Clazy.cpp b/src/Clazy.cpp
index 24c752b..dc11f10 100644
--- a/src/Clazy.cpp
+++ b/src/Clazy.cpp
@@ -82,7 +82,7 @@ bool ClazyASTConsumer::VisitDecl(Decl *decl)
         a->VisitDeclaration(decl);
 
     for (CheckBase *check : m_createdChecks) {
-        if (!(isInSystemHeader && check->ignoresAstNodesInSystemHeaders()))
+        if (!(isInSystemHeader && !check->warnsInSystemHeaders()))
             check->VisitDeclaration(decl);
     }
 
@@ -115,7 +115,7 @@ bool ClazyASTConsumer::VisitStmt(Stmt *stm)
 
     const bool isInSystemHeader = \
m_context->sm.isInSystemHeader(stm->getLocStart());  for (CheckBase *check : \
                m_createdChecks) {
-        if (!(isInSystemHeader && check->ignoresAstNodesInSystemHeaders()))
+        if (!(isInSystemHeader && !check->warnsInSystemHeaders()))
             check->VisitStatement(stm);
     }
 
diff --git a/src/checkbase.cpp b/src/checkbase.cpp
index 9e8f623..5ddd9e5 100644
--- a/src/checkbase.cpp
+++ b/src/checkbase.cpp
@@ -63,7 +63,7 @@ void ClazyPreprocessorCallbacks::MacroDefined(const Token \
&macroNameTok, const M  check->VisitMacroDefined(macroNameTok);
 }
 
-CheckBase::CheckBase(const string &name, ClazyContext *context)
+CheckBase::CheckBase(const string &name, ClazyContext *context, Options options)
     : m_sm(context->ci.getSourceManager())
     , m_name(name)
     , m_context(context)
@@ -71,6 +71,7 @@ CheckBase::CheckBase(const string &name, ClazyContext *context)
     , m_preprocessorOpts(context->ci.getPreprocessorOpts())
     , m_tu(m_astContext.getTranslationUnitDecl())
     , m_preprocessorCallbacks(new ClazyPreprocessorCallbacks(this))
+    , m_options(options)
 {
 }
 
diff --git a/src/checkbase.h b/src/checkbase.h
index 0fa5b88..a69217d 100644
--- a/src/checkbase.h
+++ b/src/checkbase.h
@@ -91,8 +91,15 @@ protected:
 class CLAZYLIB_EXPORT CheckBase
 {
 public:
+
+    enum Option {
+        Option_None = 0,
+        Option_WarnsInSystemHeaders = 1
+    };
+    typedef int Options;
+
     typedef std::vector<CheckBase*> List;
-    explicit CheckBase(const std::string &name, ClazyContext *context);
+    explicit CheckBase(const std::string &name, ClazyContext *context, Options = \
Option_None);  CheckBase(const CheckBase &other) = delete;
 
     virtual ~CheckBase();
@@ -113,7 +120,7 @@ public:
 
     virtual void registerASTMatchers(clang::ast_matchers::MatchFinder &) {};
 
-    virtual bool ignoresAstNodesInSystemHeaders() const { return true; }
+    bool warnsInSystemHeaders() const { return m_options & \
Option_WarnsInSystemHeaders; }  
 protected:
     virtual void VisitStmt(clang::Stmt *stm);
@@ -158,6 +165,7 @@ private:
     std::vector<unsigned int> m_emittedManualFixItsWarningsInMacro;
     std::vector<std::pair<clang::SourceLocation, std::string>> \
m_queuedManualInterventionWarnings;  int m_enabledFixits = 0;
+    const Options m_options;
 };
 
 #endif
diff --git a/src/checks/level2/missing-type-info.cpp \
b/src/checks/level2/missing-type-info.cpp index 3e8fb53..6d82805 100644
--- a/src/checks/level2/missing-type-info.cpp
+++ b/src/checks/level2/missing-type-info.cpp
@@ -37,7 +37,7 @@ using namespace std;
 using namespace clang;
 
 MissingTypeinfo::MissingTypeinfo(const std::string &name, ClazyContext *context)
-    : CheckBase(name, context)
+    : CheckBase(name, context, Option_WarnsInSystemHeaders) // So we visit \
Q_DECL_TYPEINFO in Qt headers  {
 }
 
diff --git a/src/checks/level2/missing-type-info.h \
b/src/checks/level2/missing-type-info.h index 2d1e248..0705a1d 100644
--- a/src/checks/level2/missing-type-info.h
+++ b/src/checks/level2/missing-type-info.h
@@ -45,7 +45,6 @@ public:
     void VisitDecl(clang::Decl *decl) override;
 private:
     void registerQTypeInfo(clang::ClassTemplateSpecializationDecl *decl);
-    bool ignoresAstNodesInSystemHeaders() const override { return false; } // So we \
visit Q_DECL_TYPEINFO in Qt headers  bool typeHasClassification(clang::QualType) \
const;  std::set<std::string> m_typeInfos;
 };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic