[Development] Qt6: Adding UTF-8 storage support to QString

Thiago Macieira thiago.macieira at intel.com
Tue Jan 22 20:41:51 CET 2019


On Tuesday, 22 January 2019 11:02:22 PST Matthew Woehlke wrote:
> On 18/01/2019 11.09, Thiago Macieira wrote:
> > As for strings, the QString constructor takes UTF-8 input, but however
> > fast
> > the decoder is, it's still slightly slower than the Latin1 decoder. So if
> > your string is purely US-ASCII, using QLatin1String is recommended.
> 
> ...but I assume QStringLiteral remains even faster? (I would think so;
> not only is *no* decoding needed, which you could also get just by using
> wide string literals, but also no *allocation*...)

Yes. In terms of CPU cycles, for a given string length of US-ASCII content:

QUtf8::convertToUnicode > qt_from_latin1 > memcpy > ∅
(fromUtf8, fromLatin1, fromUtf16, QStringLiteral)

The empty set symbol indicates that QStringLiteral is requires no operation on 
the content (O(1) on length). The others are O(n).

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center






More information about the Development mailing list