[Development] RFC: Proposal for a semi-radical change in Qt APIs taking strings

Konstantin Ritt ritt.ks at gmail.com
Sat Oct 17 05:14:58 CEST 2015


2015-10-17 6:23 GMT+04:00 Thiago Macieira <thiago.macieira at intel.com>:

> On Saturday 17 October 2015 03:34:51 Konstantin Ritt wrote:
> > - QString::fromRawData(u"hello world", 5) /* { d=nullptr, b=.., s=5 } */
> -
> > explicitly means "no owning, deep-copy when necessary"
>
> And when is it necessary?
>

In a given example, left() derives the original data, even when it isn't
shared, whilst leftRef() produces a non-shared QString, just like proposed
QStringView.
Then, all we need is to check `d != nullptr` in every non-const method and
simply COW, as usual. Modifying a back storage of a fromRawData string via
the high level isn't what we really should allow anyways.

Alternatively, it could be
    QString QString::left(int n) const { return QString(d ? d : new Data,
b, n); }
thus copying a part of the data when the original string isn't shared.
Though I don't like this idea too much.


Regards,
Konstantin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20151017/bf5a6a14/attachment.html>


More information about the Development mailing list