diff options
Diffstat (limited to 'src/core/bufferfragment_p.h')
-rw-r--r-- | src/core/bufferfragment_p.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/bufferfragment_p.h b/src/core/bufferfragment_p.h index e2154a59..a86e2922 100644 --- a/src/core/bufferfragment_p.h +++ b/src/core/bufferfragment_p.h @@ -150,6 +150,11 @@ public: return (other.size() != (int)len || memcmp(d, other.constData(), len) != 0); } + bool operator==(const BufferFragment &other) const + { + return other.len == len && !memcmp(d, other.d, len); + } + int indexOf(char c, unsigned int from = 0) const { const char *cursor = d + from - 1; @@ -190,4 +195,21 @@ private: unsigned int len; }; +uint qHash(const KConfigIniBackend::BufferFragment &fragment) +{ + const uchar *p = reinterpret_cast<const uchar*>(fragment.constData()); + const int len = fragment.length(); + + // This algorithm is copied from qhash.cpp (Qt5 version). + // Sadly this code is not accessible from the outside without going through abstraction + // layers. Even QByteArray::fromRawData would do an allocation internally... + uint h = 0; + + for (int i = 0; i < len; ++i) { + h = 31 * h + p[i]; + } + + return h; +} + #endif |