Details
-
User Story
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
-
9bf68a47e (dev), 8f68bd9e6 (dev), e1f4f2ef4 (6.8)
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!
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-99218 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
489010,16 | QString/QByteArray: add slice() methods | dev | qt/qtbase | Status: MERGED | +2 | 0 |
489011,9 | QByteArray: add slice() methods | dev | qt/qtbase | Status: ABANDONED | 0 | 0 |
489012,12 | String Views: add slice() methods | dev | qt/qtbase | Status: MERGED | +2 | 0 |
490013,1 | QString/QByteArray: add sliced() rvalue overloads | dev | qt/qtbase | Status: ABANDONED | +1 | 0 |
586725,2 | String Views: add slice() methods | 6.8 | qt/qtbase | Status: MERGED | +2 | 0 |