summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/PPToken.h
diff options
context:
space:
mode:
authorhjk <qtc-committer@nokia.com>2012-04-16 11:33:36 +0200
committerhjk <qthjk@ovi.com>2012-04-17 13:38:26 +0200
commit59debcd0e94a71498d76061966ec12d5d54c83de (patch)
tree59692929cbbcc9095f8733a4388df00e058e6f49 /src/libs/cplusplus/PPToken.h
parent0b8d8568afbe958c784f45d7daa7d6e9017872bb (diff)
downloadqt-creator-59debcd0e94a71498d76061966ec12d5d54c83de.tar.gz
preprocessor: avoid branches in tight code
Change-Id: I8dc0910f1cf11e506eb415a6f313b47ad2d41eae Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
Diffstat (limited to 'src/libs/cplusplus/PPToken.h')
-rw-r--r--src/libs/cplusplus/PPToken.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/libs/cplusplus/PPToken.h b/src/libs/cplusplus/PPToken.h
index 237ed088d6..1d63ebe59b 100644
--- a/src/libs/cplusplus/PPToken.h
+++ b/src/libs/cplusplus/PPToken.h
@@ -12,7 +12,11 @@ namespace Internal {
class CPLUSPLUS_EXPORT ByteArrayRef
{
public:
- ByteArrayRef();
+ ByteArrayRef()
+ : m_ref(&m_emptyByteArray)
+ , m_offset(0)
+ , m_length(0)
+ {}
ByteArrayRef(const QByteArray *ref)
: m_ref(ref)
@@ -32,7 +36,7 @@ public:
}
inline const char *start() const
- { return m_ref ? m_ref->constData() + m_offset : 0; }
+ { return m_ref->constData() + m_offset; }
inline int length() const
{ return m_length; }
@@ -41,16 +45,16 @@ public:
{ return length(); }
inline char at(int pos) const
- { return m_ref && pos >= 0 && pos < m_length ? m_ref->at(m_offset + pos) : '\0'; }
+ { return pos >= 0 && pos < m_length ? m_ref->at(m_offset + pos) : '\0'; }
inline char operator[](int pos) const
{ return at(pos); }
QByteArray toByteArray() const
- { return m_ref ? QByteArray(m_ref->constData() + m_offset, m_length) : QByteArray(); }
+ { return QByteArray(m_ref->constData() + m_offset, m_length); }
bool operator==(const QByteArray &other) const
- { return m_ref ? (m_length == other.length() && !qstrncmp(m_ref->constData() + m_offset, other.constData(), m_length)) : false; }
+ { return m_length == other.length() && !qstrncmp(m_ref->constData() + m_offset, other.constData(), m_length); }
bool operator!=(const QByteArray &other) const
{ return !this->operator==(other); }
@@ -59,9 +63,10 @@ public:
int count(char c) const;
private:
- const QByteArray *m_ref;
- int m_offset;
- int m_length;
+ const static QByteArray m_emptyByteArray;
+ const QByteArray * const m_ref;
+ const int m_offset;
+ const int m_length;
};
inline bool operator==(const QByteArray &other, const ByteArrayRef &ref)