"-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII" as policy in kde

Thiago Macieira thiago at kde.org
Tue Oct 5 15:46:59 BST 2010


Em Terça-feira 05 Outubro 2010, às 14:11:06, Oswald Buddenhagen escreveu:
> > This is not necessary for applications. For applications, leaving the
> > cast from ASCII is not a problem. In fact, it's slightly more efficient.
> 
> errrm, no, it isn't - quite to the contrary: comparison functions which
> have explict qlatin1string overrides are faster than with implicit
> qstring::fromascii construction. same for qchar. and the "wrapper class"
> itself is optimized away in release builds, so it doesn't add overhead.

Actually, it depends on the case.

Given the three overloads:
	function(const char *);
	function(const QLatin1String &);
	function(const QString &);

the order of overhead to call with a literal string is the order above. Of 
course, the call overhead is negligible compared to what the code does. So for 
example:

    inline QT_ASCII_CAST_WARN QString &prepend(const char *s)
    { return prepend(QString::fromAscii(s)); }

throws away the advantage. And looking at the code in qstring.h, it looks like 
most of the ASCII-cast functions are implemented in a sub-optimal way, by 
either constructing QString temporaries or QLatin1String ones. The notable 
exception is the QString constructor itself, which takes a small performance 
hit by the construction of the QLatin1String temporary.

With that in mind, I withdraw what I said: using QLatin1String is more efficient 
in the general and applications should be made to build with 
QT_NO_CAST_FROM_ASCII.

> the one gripe i have with the QLatin1* classes is the verbosity of the
> code. this makes aliases like QL1S() pretty common.

The one I have is that QLatin1String is passed by const-ref instead of by 
value.
	http://labs.qt.nokia.com/2008/04/28/string-theory/

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

Qt Developer Days 2010  -  Munich Oct 11-13  -  San Francisco Nov 1-3
For more information and to register: http://qt.nokia.com/qtdevdays2010
-------------- 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://mail.kde.org/pipermail/kde-core-devel/attachments/20101005/08ec60ad/attachment.sig>


More information about the kde-core-devel mailing list