From 8017cf63505f7ed477c658634ec882a12d3b3ddc Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 16 May 2012 17:49:32 +1000 Subject: Optimize type resolution Faster qmlType() and resolveType() lookup. Change-Id: I096439f23bf6071e8bfdf0cda366cc71e00293ba Reviewed-by: Aaron Kennedy --- src/qml/qml/ftw/qhashedstring.cpp | 21 +++++++++++++++++++++ src/qml/qml/ftw/qhashedstring_p.h | 1 + 2 files changed, 22 insertions(+) (limited to 'src/qml/qml/ftw') diff --git a/src/qml/qml/ftw/qhashedstring.cpp b/src/qml/qml/ftw/qhashedstring.cpp index 1f09d50ed3..2dc717b488 100644 --- a/src/qml/qml/ftw/qhashedstring.cpp +++ b/src/qml/qml/ftw/qhashedstring.cpp @@ -443,6 +443,27 @@ bool QHashedStringRef::startsWith(const QString &s) const QHashedString::compare(s.constData(), m_data, s.length()); } +static int findChar(const QChar *str, int len, QChar ch, int from) +{ + const ushort *s = (const ushort *)str; + ushort c = ch.unicode(); + if (from < 0) + from = qMax(from + len, 0); + if (from < len) { + const ushort *n = s + from - 1; + const ushort *e = s + len; + while (++n != e) + if (*n == c) + return n - s; + } + return -1; +} + +int QHashedStringRef::indexOf(const QChar &c, int from) const +{ + return findChar(m_data, m_length, c, from); +} + QString QHashedStringRef::toString() const { if (m_length == 0) diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index f058f21e98..f8099d508b 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -148,6 +148,7 @@ public: inline const QChar *constData() const; bool startsWith(const QString &) const; bool endsWith(const QString &) const; + int indexOf(const QChar &, int from=0) const; QHashedStringRef mid(int, int) const; inline bool isEmpty() const; -- cgit v1.2.3