QRingBuffer: improve indexOf() performance

Use memchr() instead of scan cycle.

Change-Id: Ic77a3e5ad4c5f6c7d2a1df12d150eac45d620744
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Alex Trotsenko 2015-09-03 20:38:20 +03:00
parent 352c357e6f
commit 4116fe873e
1 changed files with 6 additions and 7 deletions

View File

@ -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;
}