summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qringbuffer.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2015-09-03 20:38:20 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2015-09-03 18:31:49 +0000
commit4116fe873eae7b541d485215ce46d9224af49701 (patch)
treee0a9572b3bc3cd1798b50fbaac2a02b3c0b32acc /src/corelib/tools/qringbuffer.cpp
parent352c357e6f0785c0775a85151d6716b47aea1006 (diff)
QRingBuffer: improve indexOf() performance
Use memchr() instead of scan cycle. Change-Id: Ic77a3e5ad4c5f6c7d2a1df12d150eac45d620744 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qringbuffer.cpp')
-rw-r--r--src/corelib/tools/qringbuffer.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp
index e38245ca0a..e9b655c01e 100644
--- a/src/corelib/tools/qringbuffer.cpp
+++ b/src/corelib/tools/qringbuffer.cpp
@@ -226,16 +226,15 @@ qint64 QRingBuffer::indexOf(char c, qint64 maxLength, qint64 pos) const
index = 0;
}
- do {
- if (*ptr++ == c)
- return index + pos;
- } while (++index < nextBlockIndex);
+ const char *findPtr = reinterpret_cast<const char *>(memchr(ptr, c,
+ nextBlockIndex - index));
+ if (findPtr)
+ return qint64(findPtr - ptr) + index + pos;
- if (index == maxLength)
+ if (nextBlockIndex == maxLength)
return -1;
- } else {
- index = nextBlockIndex;
}
+ index = nextBlockIndex;
}
return -1;
}