For instance, a method such as: QLabel::setText(...)
stores the passed argument somewhere. A malloc will be needed if QStringView is the interface and a QString the passed argument. Ok, this example is not a performance critical case. I just want to highlight, that QStringView is not COW friendly. AFAIK. Philippe On Tue, 31 Jan 2017 14:09:06 +0000 Sergio Martins <[email protected]> wrote: > On 2017-01-31 12:50, Philippe wrote: > > As far as I understand, I see a performance regression with > > QStringView, for all the cases where copy-on-write can't take place > > any longer. > > In the following code, an extra malloc is needed. Or am I wrong? > > > void bar() > > { > > QString s("hello"); > > foo(s) > > } > > > void foo(QStringView sv) > > { > > QString str(sv); // malloc needed > > } > > > void foo2(const QString& s) > > { > > QString str(s); // faster because of COW > > } > > Hi Philippe, > > What will you do with str ? > If you do write operations it will detach, so the COW argument doesn't apply. > If you only do read operations then you don't even need the QString. > In fact the first malloc isn't even needed, since you could just do > foo("hello") if I understand correctly. > > > Regards, > -- Sérgio Martins | [email protected] | Senior Software Engineer > Klarälvdalens Datakonsult AB, a KDAB Group company > Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) > KDAB - The Qt, C++ and OpenGL Experts _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
