QRingBuffer: improve indexOf() performance
Use memchr() instead of scan cycle. Change-Id: Ic77a3e5ad4c5f6c7d2a1df12d150eac45d620744 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
352c357e6f
commit
4116fe873e
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue