Georg Baum wrote:
Abdelrazak Younes wrote:

Helge Hafting wrote:
Abdelrazak Younes wrote:
ucs4_to_qstring is pretty simple:

QString const ucs4_to_qstring(char_type const * str, size_t ls)
{
    QString s;

    for (size_t i = 0; i < ls; ++i)
        s.append(ucs4_to_qchar(str[i]));

    return s;
}
A function call per character - ouch.

I would be more concerned about resizing by append(). Why don't you do this?

QString const ucs4_to_qstring(char_type const * str, size_t ls)
{
        QString s;
        s.reserve(ls);
        for (size_t i = 0; i < ls; ++i)
                s.append(ucs4_to_qchar(str[i]);
        return s;
}

(assuming that QString has a reserve() member, I don't know)

It has but it makes no difference anyway.

Note that this function doesn't show in Andre's profiling results. But I
am going to inline it to see if there's a difference.

That shoudd probably be inlined.

Probably yes but I refrained doing that because we are not sure yet how we will handle the real ucs4 characters if ever (the ones that does not fit in two bytes).


Is it allowed to have a single function that understands
both ucs4 strings and QString?
What do you mean?

 Then the conversion could
be done in a single function. That tends to bring a nice speedup.

I guess Helge means
void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)

That avoids one copy operation for non-shared strings, but since IIRC
qstrings are shared I don't expect a speedup here.

Indeed and that's why I didn't bother with this at the time.

Abdel.

Reply via email to