On Thursday, 22 August 2019 14:41:51 PDT Matthew Woehlke wrote: > On 22/08/2019 17.00, Thiago Macieira wrote: > > For Qt 6, it is possible (and is still my goal[*]) to make creating a > > QString out of a QStringView and through it from a u"" literal happen > > in constant time, inlined, with no memory allocation. > > How? Unless I miss something (which your example did not show), > QStringView doesn't know if the memory to which it points is rodata or > something else. If it's something else, you can't just stick it in a > QString and hope for the best, because it could change or cease to be > allocated at any time.
You're right, it can't be done through QStringView. Only from the origina; literal, via the trick in GCC (the same that they used for std::char_traits<char>::length()) that allows us to determine if it's a string literal. Another idea that has occurred to me is to extend QStringView to carry a non- null d-pointer (without reference counting it) whenever it's created from a QString. That way, creating a QString from a QStringView that was created from a QString resumes the reference counting. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel System Software Products _______________________________________________ Development mailing list Development@qt-project.org https://lists.qt-project.org/listinfo/development