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

Bad code in QString::replace causes performance issues

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.1.0
    • None
    • Windows 7

      QString& QString::replace(const QRegExp &rx, const QString &after)
      {
      QRegExp rx2(rx);
      
      if (isEmpty() && rx2.indexIn(*this) == -1)
          return *this;
      

      That && should be ||
      The line is saying that if the string is empty and does not contain the search string, then return. Of course, if the string is empty, we already know it does not contain the search string. I would think that we would want to return if the string is empty or it does not contain the search string.

      This causes replace to always allocate memory unless the string is empty.

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

            sgaist Samuel Gaist
            jamesbloomscheff James Bloom-Scheff
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes