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

QSet subtract function is slow

    XMLWordPrintable

Details

    Description

      The function QSet::subtract is slow because of useless copy.

      The actual function is :

      Q_INLINE_TEMPLATE QSet<T> &QSet<T>::subtract(const QSet<T> &other)
      {
          QSet<T> copy1(*this);
          QSet<T> copy2(other);
          typename QSet<T>::const_iterator i = copy1.constEnd();
          while (i != copy1.constBegin()) {
              --i;
              if (copy2.contains(*i))
                  remove(*i);
          }
          return *this;
      }
      

      I propose a solution without copy :

      Q_INLINE_TEMPLATE QSet<T> &QSet<T>::subtract(const QSet<T> &other)
      {
          if(&other == this)
          {
               this.clear();
          }
          else
          {
               for(QSet<T>::iterator it = other.begin(); it != other.end(); ++it)
               {
                      this.remove(*it);
               }
          }
          return *this;
      }
      

      Note : the code with corect indentation is in attachment

      Attachments

        For Gerrit Dashboard: QTBUG-42810
        # Subject Branch Project Status CR V

        Activity

          People

            jksh Sze Howe Koh
            deac Delphine Passinge
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes