Details
-
Bug
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
dev
-
None
Description
Currently QString/QByteArray::isDetached() returns false for null strings, and in some cases for empty strings, IIUC that's because it's implemented as:
bool QString::isDetached() { return !d.isShared(); } // d is DataPointer bool QArrayDataPointer::isShared() { return !d || d->isShared(); }
Logically a null string is detached/not-shared because it has no data array to begin with.
Changing QDP::isShared() to return false when there is no d pointer
return d && d->isShared()
could solve the issue.
(And while at it, we could add a new method:
QString/QByteArray::isShared() { return d.isShared(); }
, the double negative "string is detached when its DataPointer is not shared " is harder to reason about than "string is shared when its DataPointer is shared").