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

List:       kde-commits
Subject:    [syntax-highlighting] src/lib: Use in-class member initialization where possible
From:       Dominik Haumann <null () kde ! org>
Date:       2018-07-31 19:21:18
Message-ID: E1fkaCs-0007e0-Pe () code ! kde ! org
[Download RAW message or body]

Git commit e7c7184209c5b75d1d6d7ae28621ba6f299e3e48 by Dominik Haumann.
Committed on 31/07/2018 at 19:21.
Pushed by dhaumann into branch 'master'.

Use in-class member initialization where possible

Summary: Allows to default some constructors.

Test Plan: make test

Reviewers: vkrause

Reviewed By: vkrause

Subscribers: kwrite-devel, kde-frameworks-devel

Tags: #kate, #frameworks

Differential Revision: https://phabricator.kde.org/D14499

M  +0    -11   src/lib/context.cpp
M  +5    -5    src/lib/context_p.h
M  +0    -10   src/lib/contextswitch.cpp
M  +4    -4    src/lib/contextswitch_p.h
M  +2    -8    src/lib/definition.cpp
M  +6    -6    src/lib/definition_p.h
M  +0    -7    src/lib/format.cpp
M  +4    -4    src/lib/format_p.h
M  +0    -9    src/lib/keywordlist.cpp
M  +3    -3    src/lib/keywordlist_p.h
M  +3    -4    src/lib/matchresult.cpp
M  +1    -1    src/lib/matchresult_p.h
M  +0    -6    src/lib/repository.cpp
M  +4    -3    src/lib/repository_p.h
M  +0    -12   src/lib/rule.cpp
M  +6    -6    src/lib/rule_p.h
M  +0    -5    src/lib/state.cpp
M  +2    -2    src/lib/state_p.h
M  +5    -9    src/lib/textstyledata_p.h
M  +0    -1    src/lib/themedata.cpp
M  +1    -1    src/lib/themedata_p.h

https://commits.kde.org/syntax-highlighting/e7c7184209c5b75d1d6d7ae28621ba6f299e3e48

diff --git a/src/lib/context.cpp b/src/lib/context.cpp
index a7a0760..95b3e80 100644
--- a/src/lib/context.cpp
+++ b/src/lib/context.cpp
@@ -28,17 +28,6 @@
 
 using namespace KSyntaxHighlighting;
 
-Context::Context()
-    : m_resolveState(Unknown)
-    , m_fallthrough(false)
-    , m_noIndentationBasedFolding(false)
-{
-}
-
-Context::~Context()
-{
-}
-
 Definition Context::definition() const
 {
     return m_def.definition();
diff --git a/src/lib/context_p.h b/src/lib/context_p.h
index 9752c69..f5883d7 100644
--- a/src/lib/context_p.h
+++ b/src/lib/context_p.h
@@ -33,8 +33,8 @@ namespace KSyntaxHighlighting {
 class Context
 {
 public:
-    Context();
-    ~Context();
+    Context() = default;
+    ~Context() = default;
 
     Definition definition() const;
     void setDefinition(const DefinitionRef &def);
@@ -85,9 +85,9 @@ private:
 
     QVector<Rule::Ptr> m_rules;
 
-    ResolveState m_resolveState;
-    bool m_fallthrough;
-    bool m_noIndentationBasedFolding;
+    ResolveState m_resolveState = Unknown;
+    bool m_fallthrough = false;
+    bool m_noIndentationBasedFolding = false;
 };
 }
 
diff --git a/src/lib/contextswitch.cpp b/src/lib/contextswitch.cpp
index 1e8f6d2..00b9481 100644
--- a/src/lib/contextswitch.cpp
+++ b/src/lib/contextswitch.cpp
@@ -24,16 +24,6 @@
 
 using namespace KSyntaxHighlighting;
 
-ContextSwitch::ContextSwitch() :
-    m_context(nullptr),
-    m_popCount(0)
-{
-}
-
-ContextSwitch::~ContextSwitch()
-{
-}
-
 bool ContextSwitch::isStay() const
 {
     return m_popCount == 0 && !m_context && m_contextName.isEmpty() && m_defName.isEmpty();
diff --git a/src/lib/contextswitch_p.h b/src/lib/contextswitch_p.h
index c9916c1..cbbbdeb 100644
--- a/src/lib/contextswitch_p.h
+++ b/src/lib/contextswitch_p.h
@@ -28,8 +28,8 @@ class Definition;
 class ContextSwitch
 {
 public:
-    ContextSwitch();
-    ~ContextSwitch();
+    ContextSwitch() = default;
+    ~ContextSwitch() = default;
 
     bool isStay() const;
 
@@ -42,8 +42,8 @@ public:
 private:
     QString m_defName;
     QString m_contextName;
-    Context *m_context;
-    int m_popCount;
+    Context *m_context = nullptr;
+    int m_popCount = 0;
 };
 }
 
diff --git a/src/lib/definition.cpp b/src/lib/definition.cpp
index 410b21e..fa6f299 100644
--- a/src/lib/definition.cpp
+++ b/src/lib/definition.cpp
@@ -43,14 +43,8 @@
 
 using namespace KSyntaxHighlighting;
 
-DefinitionData::DefinitionData() :
-    repo(nullptr),
-    delimiters(QStringLiteral("\t !%&()*+,-./:;<=>?[\\]^{|}~")), // must be sorted!
-    indentationBasedFolding(false),
-    caseSensitive(Qt::CaseSensitive),
-    version(0.0f),
-    priority(0),
-    hidden(false)
+DefinitionData::DefinitionData()
+    : delimiters(QStringLiteral("\t !%&()*+,-./:;<=>?[\\]^{|}~")) // must be sorted!
 {
 }
 
diff --git a/src/lib/definition_p.h b/src/lib/definition_p.h
index c31d37b..c61b0da 100644
--- a/src/lib/definition_p.h
+++ b/src/lib/definition_p.h
@@ -69,12 +69,12 @@ public:
 
     DefinitionRef q;
 
-    Repository *repo;
+    Repository *repo = nullptr;
     QHash<QString, KeywordList> keywordLists;
     QVector<Context*> contexts;
     QHash<QString, Format> formats;
     QString delimiters;
-    bool indentationBasedFolding;
+    bool indentationBasedFolding = false;
     QStringList foldingIgnoreList;
 
     QString fileName;
@@ -86,10 +86,10 @@ public:
     QString license;
     QVector<QString> mimetypes;
     QVector<QString> extensions;
-    Qt::CaseSensitivity caseSensitive;
-    int version;
-    int priority;
-    bool hidden;
+    Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive;
+    int version = 0;
+    int priority = 0;
+    bool hidden = false;
 };
 }
 
diff --git a/src/lib/format.cpp b/src/lib/format.cpp
index 06c3ad0..e2c9166 100644
--- a/src/lib/format.cpp
+++ b/src/lib/format.cpp
@@ -46,13 +46,6 @@ static Theme::TextStyle stringToDefaultFormat(const QStringRef &str)
     return static_cast<Theme::TextStyle>(value);
 }
 
-FormatPrivate::FormatPrivate()
-    : defaultStyle(Theme::Normal)
-    , id(0)
-    , spellCheck(true)
-{
-}
-
 FormatPrivate* FormatPrivate::get(const Format &format)
 {
     return format.d.data();
diff --git a/src/lib/format_p.h b/src/lib/format_p.h
index 5648b3e..8d2323f 100644
--- a/src/lib/format_p.h
+++ b/src/lib/format_p.h
@@ -30,7 +30,7 @@ namespace KSyntaxHighlighting {
 class FormatPrivate : public QSharedData
 {
 public:
-    FormatPrivate();
+    FormatPrivate() = default;
     static FormatPrivate* get(const Format &format);
 
     TextStyleData styleOverride(const Theme &theme) const;
@@ -39,9 +39,9 @@ public:
     DefinitionRef definition;
     QString name;
     TextStyleData style;
-    Theme::TextStyle defaultStyle;
-    quint16 id;
-    bool spellCheck;
+    Theme::TextStyle defaultStyle = Theme::Normal;
+    quint16 id = 0;
+    bool spellCheck = true;
 };
 
 }
diff --git a/src/lib/keywordlist.cpp b/src/lib/keywordlist.cpp
index 5b4dd15..e09c004 100644
--- a/src/lib/keywordlist.cpp
+++ b/src/lib/keywordlist.cpp
@@ -22,15 +22,6 @@
 
 using namespace KSyntaxHighlighting;
 
-KeywordList::KeywordList() :
-    m_caseSensitive(Qt::CaseSensitive)
-{
-}
-
-KeywordList::~KeywordList()
-{
-}
-
 bool KeywordList::isEmpty() const
 {
     return m_keywords.isEmpty();
diff --git a/src/lib/keywordlist_p.h b/src/lib/keywordlist_p.h
index c1a6542..e01f622 100644
--- a/src/lib/keywordlist_p.h
+++ b/src/lib/keywordlist_p.h
@@ -29,8 +29,8 @@ namespace KSyntaxHighlighting {
 class KeywordList
 {
 public:
-    KeywordList();
-    ~KeywordList();
+    KeywordList() = default;
+    ~KeywordList() = default;
 
     bool isEmpty() const;
 
@@ -50,7 +50,7 @@ private:
     QString m_name;
     QSet<QString> m_keywords;
     mutable QSet<QString> m_lowerCaseKeywords;
-    Qt::CaseSensitivity m_caseSensitive;
+    Qt::CaseSensitivity m_caseSensitive = Qt::CaseSensitive;
 };
 }
 
diff --git a/src/lib/matchresult.cpp b/src/lib/matchresult.cpp
index c6d886a..32628aa 100644
--- a/src/lib/matchresult.cpp
+++ b/src/lib/matchresult.cpp
@@ -19,10 +19,9 @@
 
 using namespace KSyntaxHighlighting;
 
-MatchResult::MatchResult(int offset, const QStringList &captures) :
-    m_captures(captures),
-    m_offset(offset),
-    m_skipOffset(0)
+MatchResult::MatchResult(int offset, const QStringList &captures)
+    : m_captures(captures)
+    , m_offset(offset)
 {
 }
 
diff --git a/src/lib/matchresult_p.h b/src/lib/matchresult_p.h
index 13972aa..bb524f9 100644
--- a/src/lib/matchresult_p.h
+++ b/src/lib/matchresult_p.h
@@ -35,7 +35,7 @@ public:
 private:
     QStringList m_captures;
     int m_offset;
-    int m_skipOffset;
+    int m_skipOffset = 0;
 };
 }
 
diff --git a/src/lib/repository.cpp b/src/lib/repository.cpp
index 3152b8a..4ab6dd9 100644
--- a/src/lib/repository.cpp
+++ b/src/lib/repository.cpp
@@ -41,12 +41,6 @@ static void initResource()
     Q_INIT_RESOURCE(syntax_data);
 }
 
-RepositoryPrivate::RepositoryPrivate() :
-    m_foldingRegionId(0),
-    m_formatId(0)
-{
-}
-
 RepositoryPrivate* RepositoryPrivate::get(Repository *repo)
 {
     return repo->d.get();
diff --git a/src/lib/repository_p.h b/src/lib/repository_p.h
index f42aca4..20ab111 100644
--- a/src/lib/repository_p.h
+++ b/src/lib/repository_p.h
@@ -32,13 +32,14 @@ class Theme;
 class RepositoryPrivate
 {
 public:
-    RepositoryPrivate();
+    RepositoryPrivate() = default;
 
     static RepositoryPrivate* get(Repository *repo);
 
     void load(Repository *repo);
     void loadSyntaxFolder(Repository *repo, const QString &path);
     bool loadSyntaxFolderFromIndex(Repository *repo, const QString &path);
+
     void addDefinition(const Definition &def);
 
     void loadThemeFolder(const QString &path);
@@ -55,8 +56,8 @@ public:
     QVector<Theme> m_themes;
 
     QHash<QPair<QString, QString>, quint16> m_foldingRegionIds;
-    quint16 m_foldingRegionId;
-    quint16 m_formatId;
+    quint16 m_foldingRegionId = 0;
+    quint16 m_formatId = 0;
 };
 }
 
diff --git a/src/lib/rule.cpp b/src/lib/rule.cpp
index c803309..6d1f843 100644
--- a/src/lib/rule.cpp
+++ b/src/lib/rule.cpp
@@ -85,18 +85,6 @@ static QString replaceCaptures(const QString &pattern, const QStringList &captur
     return result;
 }
 
-Rule::Rule() :
-    m_column(-1),
-    m_firstNonSpace(false),
-    m_lookAhead(false),
-    m_dynamic(false)
-{
-}
-
-Rule::~Rule()
-{
-}
-
 Definition Rule::definition() const
 {
     return m_def.definition();
diff --git a/src/lib/rule_p.h b/src/lib/rule_p.h
index 2532e6e..a1cb2ce 100644
--- a/src/lib/rule_p.h
+++ b/src/lib/rule_p.h
@@ -38,8 +38,8 @@ namespace KSyntaxHighlighting {
 class Rule
 {
 public:
-    Rule();
-    virtual ~Rule();
+    Rule() = default;
+    virtual ~Rule() = default;
 
     typedef std::shared_ptr<Rule> Ptr;
 
@@ -76,12 +76,12 @@ private:
     QString m_attribute;
     ContextSwitch m_context;
     QVector<Rule::Ptr> m_subRules;
-    int m_column;
+    int m_column = -1;
     FoldingRegion m_beginRegion;
     FoldingRegion m_endRegion;
-    bool m_firstNonSpace;
-    bool m_lookAhead;
-    bool m_dynamic;
+    bool m_firstNonSpace = false;
+    bool m_lookAhead = false;
+    bool m_dynamic = false;
 };
 
 
diff --git a/src/lib/state.cpp b/src/lib/state.cpp
index bd8c866..0159ba5 100644
--- a/src/lib/state.cpp
+++ b/src/lib/state.cpp
@@ -24,11 +24,6 @@
 
 using namespace KSyntaxHighlighting;
 
-StateData::StateData() :
-    m_defData(nullptr)
-{
-}
-
 StateData* StateData::get(State &state)
 {
     state.d.detach();
diff --git a/src/lib/state_p.h b/src/lib/state_p.h
index dd71a6c..4913232 100644
--- a/src/lib/state_p.h
+++ b/src/lib/state_p.h
@@ -34,7 +34,7 @@ class DefinitionData;
 class StateData : public QSharedData
 {
 public:
-    StateData();
+    StateData() = default;
     static StateData* get(State &state);
 
     bool isEmpty() const;
@@ -45,7 +45,7 @@ public:
     Context* topContext() const;
     QStringList topCaptures() const;
 
-    DefinitionData *m_defData;
+    DefinitionData *m_defData = nullptr;
 private:
     friend class State;
     QStack<Context*> m_contextStack;
diff --git a/src/lib/textstyledata_p.h b/src/lib/textstyledata_p.h
index d527fb2..f5f7cfa 100644
--- a/src/lib/textstyledata_p.h
+++ b/src/lib/textstyledata_p.h
@@ -27,11 +27,7 @@ class TextStyleData
 public:
     // Constructor initializing all data.
     TextStyleData()
-        : textColor(0x0)
-        , backgroundColor(0x0)
-        , selectedTextColor(0x0)
-        , selectedBackgroundColor(0x0)
-        , bold(false)
+        : bold(false)
         , italic(false)
         , underline(false)
         , strikeThrough(false)
@@ -41,10 +37,10 @@ public:
         , hasStrikeThrough(false)
     {}
 
-    QRgb textColor;
-    QRgb backgroundColor;
-    QRgb selectedTextColor;
-    QRgb selectedBackgroundColor;
+    QRgb textColor = 0x0;
+    QRgb backgroundColor = 0x0;
+    QRgb selectedTextColor = 0x0;
+    QRgb selectedBackgroundColor = 0x0;
     bool bold :1;
     bool italic :1;
     bool underline :1;
diff --git a/src/lib/themedata.cpp b/src/lib/themedata.cpp
index 9abda83..ae9971d 100644
--- a/src/lib/themedata.cpp
+++ b/src/lib/themedata.cpp
@@ -36,7 +36,6 @@ ThemeData* ThemeData::get(const Theme &theme)
 }
 
 ThemeData::ThemeData()
-    : m_revision(0)
 {
     memset(m_editorColors, 0, sizeof(m_editorColors));
 }
diff --git a/src/lib/themedata_p.h b/src/lib/themedata_p.h
index 7a033cc..b13fe8f 100644
--- a/src/lib/themedata_p.h
+++ b/src/lib/themedata_p.h
@@ -136,7 +136,7 @@ public:
     TextStyleData textStyleOverride(const QString &definitionName, const QString &attributeName) const;
 
 private:
-    int m_revision;
+    int m_revision = 0;
     QString m_name;
 
     //! Path to the file where the theme came from.
[prev in list] [next in list] [prev in thread] [next in thread] 

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