Details
-
User Story
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
E.g., it's nice that we have sliced() now, as a saner alternative to mid(), but that name is suggestive of the possibility to also have slice(). And I'd also like to have sliced() && as an optimisation for when ref-count == 1. Indeed, having worked on Qt's internal QRingBuffer class, I see code that desperately tries to work around the lack of slice():
if (isShared()) return chunk.mid(headOffset, size()); if (headOffset != 0) { char *ptr = chunk.data(); ::memmove(ptr, ptr + headOffset, size()); tailOffset -= headOffset; headOffset = 0; } chunk.resize(tailOffset);
The middle part is, of course, QByteArray::remove(0, headOffset). So, yes, I can emulate this function by two calls to resize and remove(0, .), but at the cost of two calls (and, as you can see, it's important to get their order right - the above moves too much data).
So, pretty please, add slice() and sliced() && to all containers that have sliced()?
Thanks!