Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-99218

As a user of Qt, I'd like the string-like classes to have substringing actions, not just transformations

    XMLWordPrintable

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!

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            cnn Qt Core & Network
            mmutz Marc Mutz
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes