[Development] QLatin1Constant and QtContacts / QtOrganizer

Thiago Macieira thiago.macieira at intel.com
Tue Dec 20 16:32:18 CET 2011


On Tuesday, 20 de December de 2011 15.57.21, Robin Burchell wrote:
> On Tue, Dec 20, 2011 at 3:54 PM, Harald Fernengel
> 
> <harald.fernengel at nokia.com> wrote:
> > I thought about optimizing ::fromUtf8, but since we need to iterate
> > character by character to convert the char* to utf16, the length of the
> > string should be rather irrelevant?
> 
> having the length would at least allow you to semi-sensibly reserve()
> a size that's at least close to what the utf16 size would be, though,
> wouldn't it?

Yes. A UTF-8 encoded string is always the same length or longer than the UCS-4 
or UTF-16 string, just as the UTF-16 one is the same length or longer than the 
UCS-4 one.

Having the length allows us to do one malloc only. Without it, we'll need to 
realloc several times to grow.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20111220/626bfde1/attachment.sig>


More information about the Development mailing list