2010-12-19 Paolo Carlini <paolo.carlini@oracle.com>
+ * include/bits/basic_string.h (operator+(basic_string<>&&,
+ basic_string<>&&)): Optimize better.
+ * include/ext/vstring.h (operator+(__versa_string<>&&,
+ __versa_string<>&)): Likewise.
+
+2010-12-19 Paolo Carlini <paolo.carlini@oracle.com>
+
* testsuite/21_strings/basic_string/operators/char/4.cc: New.
* testsuite/21_strings/basic_string/operators/wchar_t/4.cc: Likewise.
* testsuite/ext/vstring/operators/2.cc: Likewise.
inline basic_string<_CharT, _Traits, _Alloc>
operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
basic_string<_CharT, _Traits, _Alloc>&& __rhs)
- { return std::move(__lhs.append(__rhs)); }
+ {
+ const auto __size = __lhs.size() + __rhs.size();
+ const bool __cond = (__size > __lhs.capacity()
+ && __size <= __rhs.capacity());
+ return __cond ? std::move(__rhs.insert(0, __lhs))
+ : std::move(__lhs.append(__rhs));
+ }
template<typename _CharT, typename _Traits, typename _Alloc>
inline basic_string<_CharT, _Traits, _Alloc>
template<typename _CharT, typename _Traits, typename _Alloc>
inline basic_string<_CharT, _Traits, _Alloc>
- operator+(_CharT __lhs, basic_string<_CharT,
- _Traits, _Alloc>&& __rhs)
+ operator+(_CharT __lhs,
+ basic_string<_CharT, _Traits, _Alloc>&& __rhs)
{ return std::move(__rhs.insert(0, 1, __lhs)); }
template<typename _CharT, typename _Traits, typename _Alloc>
inline __versa_string<_CharT, _Traits, _Alloc, _Base>
operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
__versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
- { return std::move(__lhs.append(__rhs)); }
+ {
+ const auto __size = __lhs.size() + __rhs.size();
+ const bool __cond = (__size > __lhs.capacity()
+ && __size <= __rhs.capacity());
+ return __cond ? std::move(__rhs.insert(0, __lhs))
+ : std::move(__lhs.append(__rhs));
+ }
template<typename _CharT, typename _Traits, typename _Alloc,
template <typename, typename, typename> class _Base>