summaryrefslogtreecommitdiffstats
path: root/src/corelib/mimetypes/qmimemagicrule_p.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-07-25 12:24:20 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-02-17 16:17:37 +0000
commit773458ad633c68e9111888b71f8971064cf42fd3 (patch)
treeae20e1722c2ef193d08ab365b5efb4030913e173 /src/corelib/mimetypes/qmimemagicrule_p.h
parent30b0c346ec9bfe3730aa1a5a77199a3b0e61c1f8 (diff)
Remove QMimeMagicRule's pimpl
It didn't make the class implicitly shared, but required an additional heap allocation on construction and copy, as it used 'only' QScopedPointer. As it's private API the pimpl is also not needed for BC reasons. So inline the data members, and some trivial accessors. As a by-product of removing the copy special member functions, we gain nothrow move special member functions. Interestingly, the memory layout of a QList<QMimeMagicRule> (replacing which is the topic of a future patch) doesn't change due to this change, because the type that formerly fit QList very well now is too large. But copying the type outside QList now no longer allocates memory. Saves more than 2.5KiB in text size on optimized GCC 5.3 Linux AMD64 builds. Change-Id: Ie3588cb5693227da6f1bfa196db924e075a750b3 Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/mimetypes/qmimemagicrule_p.h')
-rw-r--r--src/corelib/mimetypes/qmimemagicrule_p.h34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/corelib/mimetypes/qmimemagicrule_p.h b/src/corelib/mimetypes/qmimemagicrule_p.h
index 84c2fe2174..1a6ca81e11 100644
--- a/src/corelib/mimetypes/qmimemagicrule_p.h
+++ b/src/corelib/mimetypes/qmimemagicrule_p.h
@@ -61,7 +61,6 @@
QT_BEGIN_NAMESPACE
-class QMimeMagicRulePrivate;
class QMimeMagicRule
{
public:
@@ -69,20 +68,16 @@ public:
QMimeMagicRule(const QString &typeStr, const QByteArray &value, const QString &offsets,
const QByteArray &mask, QString *errorString);
- QMimeMagicRule(const QMimeMagicRule &other);
- ~QMimeMagicRule();
-
- QMimeMagicRule &operator=(const QMimeMagicRule &other);
bool operator==(const QMimeMagicRule &other) const;
- Type type() const;
- QByteArray value() const;
- int startPos() const;
- int endPos() const;
+ Type type() const { return m_type; }
+ QByteArray value() const { return m_value; }
+ int startPos() const { return m_startPos; }
+ int endPos() const { return m_endPos; }
QByteArray mask() const;
- bool isValid() const;
+ bool isValid() const { return m_matchFunction != Q_NULLPTR; }
bool matches(const QByteArray &data) const;
@@ -94,7 +89,24 @@ public:
static bool matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, int valueLength, const char *valueData, const char *mask);
private:
- const QScopedPointer<QMimeMagicRulePrivate> d;
+ Type m_type;
+ QByteArray m_value;
+ int m_startPos;
+ int m_endPos;
+ QByteArray m_mask;
+
+ QByteArray m_pattern;
+ quint32 m_number;
+ quint32 m_numberMask;
+
+ typedef bool (QMimeMagicRule::*MatchFunction)(const QByteArray &data) const;
+ MatchFunction m_matchFunction;
+
+private:
+ // match functions
+ bool matchString(const QByteArray &data) const;
+ template <typename T>
+ bool matchNumber(const QByteArray &data) const;
};
Q_DECLARE_TYPEINFO(QMimeMagicRule, Q_MOVABLE_TYPE);