BString: add support for move semantics with C++11 and up.
This implements the "rule of 5" for this type. While the copy operation for BString was already using shallow copies of the underlying data, this change further optimizes moving the data from one object to another. While it is not the intention to implement move semantics to all types in the legacy Haiku/Be kits, data types like BString are good candidates, because move operations are often useful when working with data within an application. In this implementation, the internal data of the string object will be set to NULL, thus leaving an empty string. Change-Id: I16bf9424f9b17f622b0b57659b80628e18760288 Reviewed-on: https://review.haiku-os.org/c/haiku/+/4428 Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
Jérôme Duval
parent
3cf06bfc6b
commit
0b86520c4d
@@ -40,7 +40,7 @@
|
||||
strings. For all operations that perform on bytes, there is an equivalent
|
||||
that operates on UTF-8 strings. See for example the BString::CopyInto() and
|
||||
BString::CopyCharsInto() methods. The main difference is that if there are
|
||||
any position argumens, the regular method counts the bytes and the
|
||||
any position argumens, the regular method counts the bytes and the
|
||||
Chars methods counts characters.
|
||||
|
||||
\since BeOS R5
|
||||
@@ -94,6 +94,21 @@
|
||||
*/
|
||||
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
/*!
|
||||
\fn BString::BString(BString&& string)
|
||||
\brief Move the data from the \a string to this object.
|
||||
|
||||
Create a new string object with the data of another \a string. The
|
||||
\a string will no longer point to the same contents.
|
||||
|
||||
\note This constructor is only available for modern C++ (C++11 or later).
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
\fn BString::~BString()
|
||||
\brief Free all resources associated with the object.
|
||||
@@ -270,6 +285,22 @@
|
||||
*/
|
||||
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
/*!
|
||||
\fn BString& BString::operator=(BString&& string)
|
||||
\brief Move the contents of \a string to this BString object.
|
||||
|
||||
The \a string will no longer point to the same contents.
|
||||
|
||||
\note This method is only available for modern C++ (C++11 or later).
|
||||
|
||||
\return This method always returns \c *this.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
\fn BString& BString::SetTo(const char* str)
|
||||
\brief Re-initialize the BString to a copy of the data of a string.
|
||||
|
||||
Reference in New Issue
Block a user