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

JS TypedArrays conversion to C++ is weird

    XMLWordPrintable

Details

    Description

      Repro: here the following code gives a QVariantMap of QVariants which hold doubles, which is incredibly wasteful. In addition, since it is lexicographically sorted, the order will be 0, 1, 10, 11, 12, ..., 2, 20, 21, ...

      #include <QCoreApplication>
      #include <QDebug>
      #include <QJSEngine>
      int main(int argc, char *argv[]) {
        qputenv("QT_ASSUME_STDERR_HAS_CONSOLE", "1");
      
        QCoreApplication a(argc, argv);
      
        QJSEngine e;
        auto res = e.evaluate(R"_(
      let arr = new Float64Array(15);
      for(let i = 0; i < 15; i++)
        arr[i] = i;
      
      arr;
      )_");
      
        qDebug() << res.toVariant();
       /* Prints: 
           QVariant(QVariantMap, QMap(("0", QVariant(double, 0))("1", QVariant(double, 1))("10", QVariant(double, 10))("11", QVariant(double, 11))("12", QVariant(double, 12))("13", QVariant(double, 13))("14", QVariant(double, 14))("2", QVariant(double, 2))("3", QVariant(double, 3))("4", QVariant(double, 4))("5", QVariant(double, 5))("6", QVariant(double, 6))("7", QVariant(double, 7))("8", QVariant(double, 8))("9", QVariant(double, 9))))
         */
      }
      

      Is there any way to make this return at least a list instead of a map? The ideal would be to get a QVector<T> or even more ideally a view type such as std::span<T> if one takes care of keeping the QSJValue alive while work is being done with it...

      e.g. I'd expect

      qjsvalue_cast<QVector<double>>(res);
      

      to at least give something given a Float64Array

      Attachments

        1. trace.png
          trace.png
          278 kB
        2. trace2.png
          trace2.png
          116 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            jcelerier Jean-Michaël Celerier
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes