Handling of const strings/char arrays, e.g. with KActionCollection

Thiago Macieira thiago at kde.org
Tue Apr 22 18:41:13 BST 2008


On Tuesday 22 April 2008 18:58:35 Friedrich W. H. Kossebau wrote:
> Now I could go and wrap all strings with QLatin1String on the caller side.
> Another, perhaps more simple fix would be to overload all functions with
> their const-char* equivalents as convenience functions, which internally
> call the old one using QLatin1String.
> What is to be preferred? How costly are the additional symbols in the
> library against all the explicit QLatin1String calls in the binary code,
> which are also making the source code harder to read? Any idea?
> Should I prepare such a patch for KActionCollection?

There's no gain in performance or memory allocation. You shouldn't keep 
objects of type QLatin1String around, since they don't do deep copies. The 
QLatin1String class is just there so you can easily mark your code for "this 
is Latin 1" and avoid using QString::fromLatin1(). It's meant to be converted 
to QString later.

In some operations, like indexOf, replace, endsWith, etc., QString has a 
QLatin1String overload. In that case, there is a gain in performance since no 
extra QString is allocated. I.e., you invoke the Latin 1 comparison functions 
(where they exist), which are cheaper.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080422/0604b636/attachment.sig>


More information about the kde-core-devel mailing list