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

Avoid unnecessary copy in QByteArray::toDouble when created via fromRawData

    XMLWordPrintable

Details

    Description

      Currently if we need to convert const char* to double in Qt, we must use QString::toDouble() or QByteArray::toDouble().

      For example:

      const char *text = "1234.56";
      
      double d1 = QString::fromLatin1(text).toDouble();
      
      double d2 = QByteArray::fromRawData(text, qstrlen(text)).toDouble()
      

      But in both cases this results in unnecessary memory allocation.

      I'm looking for some fast way to convert const char* to double, and I thought it would be nice if QLatin1String class have toDouble(), toLongLong(), etc. methods.

      These methods could be used for example, in QPSQL driver to speed-up fetching large query results (100k+ rows) - for each double value in row we must do a conversion from const char* to double. There are standard C functions: atof(), atol(), but they use system locale, and can't be used in QPSQL.

      Another solution would be to make the following functions available in public API:

      qstrtod()
      qstrntod()
      qstrtoll()
      qstrtoull()
      

      from qtbase/src/corelib/tools/qlocale_tools_p.h

      Attachments

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

        Activity

          People

            vhilshei Volker Hilsheimer
            amiart Robert Szefner
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes