[Development] Feature Freeze Exception: QStringView
Александр Волков
a.volkov at rusbitech.ru
Wed Feb 1 16:09:17 CET 2017
01.02.2017 17:22, Marc Mutz пишет:
> Ah, nevermind, 'found' is a QString_List_.
>
> I'm curious how a non-implicitly-shared string type would help you there,
> though. You can always clear() (or, in case of QVector<QString>, std::move())
> the string, and capacity is left with the sole owner in the container.
QString s1;
s1.reserve(1024);
s1.resize(100, '*');
qDebug() << s1.capacity(); // 1024
QString s2 = s1;
s1[0] = '-';
qDebug() << s1.capacity(); // 100
qDebug() << s2.capacity(); // 1024
With non-implicitly-shared string the capacity of s1 won't change.
The idea of readLineInto() is to avoid memory allocations by writing
into the pre-allocated buffer.
But when readLineInto() is trying to write into an implicitly shared
string buffer,
then the content of the buffer is copied and readLineInto() writes into
the copy.
More information about the Development
mailing list