Introduce QArrayDataPointer::needsDetach
authorJoão Abecasis <joao.abecasis@nokia.com>
Thu, 16 Feb 2012 22:28:30 +0000 (23:28 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 2 Apr 2012 14:34:21 +0000 (16:34 +0200)
commit5e82bb9e6fe71fda6befecf6019e8248846a3fda
treeb9fc62a6af2f34795ff35443d2ee884b523eec4b
parent15e3ae6b9da9b32236d3e3348ede86c3acf06fb4
Introduce QArrayDataPointer::needsDetach

While QArrayDataPointer offers generic detach() functionality, this is
only useful for operations that may modify data, but don't otherwise
affect the container itself, such as non-const iteration, front() and
back().

For other modifying operations, users of the API typically need to
decide whether a detach is needed based on QArrayData's requirements
(is data mutable? is it currently shared?) and its own (do we have
spare capacity for growth?).

Now that data may be shared, static or otherwise immutable (e.g.,
fromRawData) it no longer suffices to check the ref-count for
isShared().

This commit adds needsDetach() which, from the point-of-view of
QArrayData(Pointer), answers the question: 'Can contained data and
associated metadata be changed?'.

This fixes QArrayDataPointer::setSharable for static data (e.g.,
Q_ARRAY_LITERAL), previously it only catered to shared_null.
SimpleVector is also fixed since it wasn't checking Mutability and it
needs to because it supports fromRawData().

Change-Id: I3c7f9c85c83dfd02333762852fa456208e96d5ad
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/tools/qarraydatapointer.h
tests/auto/corelib/tools/qarraydata/simplevector.h