On Tuesday, 20 de December de 2011 15.57.21, Robin Burchell wrote:
> On Tue, Dec 20, 2011 at 3:54 PM, Harald Fernengel
>
> <[email protected]> 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

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to