summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qloggingregistry_p.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-02-07 22:29:45 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-04-10 14:54:31 +0000
commit46c66bce5de04396292600b0c2c87c2468a02102 (patch)
treeb801f976107782b62e305fdb31d1284fe5691803 /src/corelib/io/qloggingregistry_p.h
parentdb29042588ac406b46ec431badc2c12a5d3a8d56 (diff)
Optimize QLoggingSettingsParser
Factor the line parsing into a separate function, parseNextLine(), taking a QStringRef. In setContent(QTextStream&), use the new readLineInto() function to re-use the capacity of a single QString for all lines. In setContent(QString), use splitRef() to split the lines. In either function, pass each line to parseNextLine(). In order to port all the parsing to QStringRef, I needed to make some semantic changes: the old code removed all whitespace right at the beginning. This is not possible with QStringRef. It also didn't feel right, since a line like [ r u l e s ] would successfully parse as the section named "rules". I added trimmed() calls at the beginning, and around the valueStr and pattern extraction, which should be good enough. Also, when a section is found, don't store it anymore. Instead, only store whether it was the [rules] section, because that's all we'll test for. That way, we don't have to convert QStringRefs to QString just to store them across parseNextLine() calls. Replace the setSection() function with setImplicitRulesSection(), because "rules" is all that was ever passed. This is private API, we can bring back some of the dropped flexibility later, as needed. [ChangeLog][Important Behavior Changes] Logging rules can no longer contain arbitrary whitespace such as within a category identifier. Change-Id: Ic26cd23c71f5c810b37ef4b972354ac31d3408fe Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/corelib/io/qloggingregistry_p.h')
-rw-r--r--src/corelib/io/qloggingregistry_p.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/io/qloggingregistry_p.h b/src/corelib/io/qloggingregistry_p.h
index 23740c4955..69fc6ea4ec 100644
--- a/src/corelib/io/qloggingregistry_p.h
+++ b/src/corelib/io/qloggingregistry_p.h
@@ -93,7 +93,7 @@ Q_DECLARE_TYPEINFO(QLoggingRule, Q_MOVABLE_TYPE);
class Q_AUTOTEST_EXPORT QLoggingSettingsParser
{
public:
- void setSection(const QString &section) { _section = section; }
+ void setImplicitRulesSection(bool inRulesSection) { m_inRulesSection = inRulesSection; }
void setContent(const QString &content);
void setContent(QTextStream &stream);
@@ -101,7 +101,10 @@ public:
QVector<QLoggingRule> rules() const { return _rules; }
private:
- QString _section;
+ void parseNextLine(QStringRef line);
+
+private:
+ bool m_inRulesSection = false;
QVector<QLoggingRule> _rules;
};