From 97069c2274ee090bd80503d66e01859059460050 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 18 Apr 2012 12:04:05 +0200 Subject: [PATCH] preprocessor: streamline ByteArrayRef Change-Id: Iec09651a6aa2fe3b8a50e631fd2fdc57830892a5 Reviewed-by: Thomas Hartmann --- src/libs/cplusplus/PPToken.cpp | 2 -- src/libs/cplusplus/PPToken.h | 23 +++++++++-------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/libs/cplusplus/PPToken.cpp b/src/libs/cplusplus/PPToken.cpp index 670b80bad84..5b20c826c7b 100644 --- a/src/libs/cplusplus/PPToken.cpp +++ b/src/libs/cplusplus/PPToken.cpp @@ -4,8 +4,6 @@ using namespace CPlusPlus::Internal; -const QByteArray ByteArrayRef::m_emptyByteArray; - bool ByteArrayRef::startsWith(const char *s) const { int l = std::strlen(s); diff --git a/src/libs/cplusplus/PPToken.h b/src/libs/cplusplus/PPToken.h index c5b7ef1ee90..fe27092d08b 100644 --- a/src/libs/cplusplus/PPToken.h +++ b/src/libs/cplusplus/PPToken.h @@ -13,20 +13,17 @@ class CPLUSPLUS_EXPORT ByteArrayRef { public: ByteArrayRef() - : m_ref(&m_emptyByteArray) - , m_offset(0) + : m_start("") , m_length(0) {} ByteArrayRef(const QByteArray *ref) - : m_ref(ref) - , m_offset(0) + : m_start(ref->constData()) , m_length(ref->length()) {} ByteArrayRef(const QByteArray *ref, int offset, int length) - : m_ref(ref) - , m_offset(offset) + : m_start(ref->constData() + offset) , m_length(length) { Q_ASSERT(ref); @@ -36,7 +33,7 @@ public: } inline const char *start() const - { return m_ref->constData() + m_offset; } + { return m_start; } inline int length() const { return m_length; } @@ -45,21 +42,21 @@ public: { return length(); } inline char at(int pos) const - { return pos >= 0 && pos < m_length ? m_ref->at(m_offset + pos) : '\0'; } + { return pos >= 0 && pos < m_length ? m_start[pos] : '\0'; } inline char operator[](int pos) const { return at(pos); } QByteArray toByteArray() const - { return QByteArray(m_ref->constData() + m_offset, m_length); } + { return QByteArray(m_start, m_length); } bool operator==(const QByteArray &other) const - { return m_length == other.length() && !qstrncmp(m_ref->constData() + m_offset, other.constData(), m_length); } + { return m_length == other.length() && !qstrncmp(m_start, other.constData(), m_length); } bool operator!=(const QByteArray &other) const { return !this->operator==(other); } bool operator==(const char *other) const - { return qstrncmp(m_ref->constData() + m_offset, other, strlen(other)) == 0; } + { return qstrncmp(m_start, other, strlen(other)) == 0; } bool operator!=(const char *other) const { return !this->operator==(other); } @@ -68,9 +65,7 @@ public: int count(char c) const; private: - const static QByteArray m_emptyByteArray; - const QByteArray * const m_ref; - const int m_offset; + const char *m_start; const int m_length; };