diff options
Diffstat (limited to 'libstdc++-v3/include/ext/sso_string_base.h')
-rw-r--r-- | libstdc++-v3/include/ext/sso_string_base.h | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/libstdc++-v3/include/ext/sso_string_base.h b/libstdc++-v3/include/ext/sso_string_base.h index c37bd88ca5a..bd29413eb83 100644 --- a/libstdc++-v3/include/ext/sso_string_base.h +++ b/libstdc++-v3/include/ext/sso_string_base.h @@ -47,8 +47,8 @@ namespace __gnu_cxx typedef typename _Traits::char_type value_type; typedef _Alloc allocator_type; - typedef typename __vstring_utility<_CharT, _Traits, _Alloc>:: - _CharT_alloc_type _CharT_alloc_type; + typedef __vstring_utility<_CharT, _Traits, _Alloc> _Util_Base; + typedef typename _Util_Base::_CharT_alloc_type _CharT_alloc_type; typedef typename _CharT_alloc_type::size_type size_type; private: @@ -66,18 +66,9 @@ namespace __gnu_cxx enum { _S_max_size = (((static_cast<size_type>(-1) / sizeof(_CharT)) - 1) / 4) }; - // Use empty-base optimization: http://www.cantrip.org/emptyopt.html - struct _Alloc_hider : _Alloc - { - _Alloc_hider(const _Alloc& __a, _CharT* __ptr) - : _Alloc(__a), _M_p(__ptr) { } - - _CharT* _M_p; // The actual data. - }; - // Data Members (private): - _Alloc_hider _M_dataplus; - size_type _M_string_length; + typename _Util_Base::template _Alloc_hider<_Alloc> _M_dataplus; + size_type _M_string_length; enum { _S_local_capacity = 15 }; @@ -87,9 +78,9 @@ namespace __gnu_cxx size_type _M_allocated_capacity; }; - _CharT* + void _M_data(_CharT* __p) - { return (_M_dataplus._M_p = __p); } + { _M_dataplus._M_p = __p; } void _M_length(size_type __length) @@ -118,7 +109,7 @@ namespace __gnu_cxx _M_destroy(size_type) throw(); // _M_construct_aux is used to implement the 21.3.1 para 15 which - // requires special behaviour if _InIter is an integral type + // requires special behaviour if _InIterator is an integral type template<class _InIterator> void _M_construct_aux(_InIterator __beg, _InIterator __end, __false_type) @@ -181,28 +172,19 @@ namespace __gnu_cxx _M_is_shared() const { return false; } - bool - _M_is_leaked() const - { return false; } - void - _M_set_sharable() { } + _M_set_leaked() { } void - _M_set_leaked() { } + _M_leak() { } void _M_set_length(size_type __n) { _M_length(__n); - // grrr. (per 21.3.4) - // You cannot leave those LWG people alone for a second. traits_type::assign(_M_data()[__n], _CharT()); } - void - _M_leak() { } - __sso_string_base() : _M_dataplus(_Alloc(), _M_local_data) { _M_set_length(0); } @@ -248,6 +230,9 @@ namespace __gnu_cxx __sso_string_base<_CharT, _Traits, _Alloc>:: _M_swap(__sso_string_base& __rcs) { + // NB: Implement Option 3 of DR 431 (see N1599). + _M_dataplus._M_alloc_swap(__rcs._M_dataplus); + if (_M_is_local()) if (__rcs._M_is_local()) { @@ -325,9 +310,6 @@ namespace __gnu_cxx // The below implements an exponential growth policy, necessary to // meet amortized linear time requirements of the library: see // http://gcc.gnu.org/ml/libstdc++/2001-07/msg00085.html. - // It's active for allocations requiring an amount of memory above - // system pagesize. This is consistent with the requirements of the - // standard: http://gcc.gnu.org/ml/libstdc++/2001-07/msg00130.html if (__capacity > __old_capacity && __capacity < 2 * __old_capacity) __capacity = 2 * __old_capacity; @@ -373,7 +355,6 @@ namespace __gnu_cxx _M_construct(_InIterator __beg, _InIterator __end, std::input_iterator_tag) { - // Avoid reallocation for common case. size_type __len = 0; size_type __capacity = size_type(_S_local_capacity); @@ -418,7 +399,7 @@ namespace __gnu_cxx std::forward_iterator_tag) { // NB: Not required, but considered best practice. - if (__builtin_expect(__is_null_p(__beg) && __beg != __end, 0)) + if (__builtin_expect(_S_is_null_pointer(__beg) && __beg != __end, 0)) std::__throw_logic_error(__N("__sso_string_base::" "_M_construct NULL not valid")); |