Commit 7697e6c6 by Paolo Carlini Committed by Paolo Carlini

rc_string_base.h (__rc_string_base<>::_Rep): Avoid the anonymous struct…

rc_string_base.h (__rc_string_base<>::_Rep): Avoid the anonymous struct extension, adjust everywhere.

2005-11-18  Paolo Carlini  <pcarlini@suse.de>

	* include/ext/rc_string_base.h (__rc_string_base<>::_Rep): Avoid the
	anonymous struct extension, adjust everywhere.

	* include/ext/rc_string_base.h (__rc_string_base<>::_S_empty_rep()):
	Just use a static member.
	(__rc_string_base<>::__rc_string_base(), _S_construct): Adjust.

	* include/ext/rc_string_base.h (__rc_string_base<>::_Rep): Use anonymous
	union together with _CharT to fix alignment issues, rebind to _Rep and
	rename _Raw_alloc to _Rep_alloc_type.
	(__rc_string_base<>::_Rep::_S_create, _M_destroy): Adjust consistently.

	* include/ext/vstring_util.h (__is_null_p): Move inside struct
	__vstring_utility as static _S_is_null_pointer.
	* include/ext/sso_string.h
	(__sso_string_base<>::_M_construct(std::forward_iterator_tag): Adjust.
	* include/ext/rc_string_base.h
	(__rc_string_base<>::_S_construct(std::forward_iterator_tag): Likewise.

	Implement Option 3 of DR 431 for ext/vstring - both available bases.
	* include/bits/cpp_type_traits.h (struct __is_empty): Add.
	* include/ext/vstring.h (__versa_string<>::swap): Delegate to
	this->_M_swap.
	* include/ext/vstring.tcc (__versa_string<>::swap): Remove.
	* include/ext/vstring_util.h (struct __vstring_utility<>): Add struct
	_Alloc_hider<>, augmented of allocator swapping facility, specialized
	to nop for empty allocators.
	* include/ext/rc_string_base.h (__rc_string_base<>::_M_swap): Use it.
	(__rc_string_base<>::_M_is_leaked, _M_set_sharable): Change to private.
	* include/ext/sso_string_base.h	(__sso_string_base<>::_M_swap):
	Likewise.
	(__sso_string_base<>::_M_is_leaked, _M_set_sharable): Remove, unused.	

	* include/ext/rc_string_base.h (__rc_string_base<>::_M_data(_CharT*):
	Return void.
	* include/ext/sso_string_base.h (__sso_string_base<>::_M_data(_CharT*):
	Likewise.

From-SVN: r107176
parent e0709888
2005-11-18 Paolo Carlini <pcarlini@suse.de>
* include/ext/rc_string_base.h (__rc_string_base<>::_Rep): Avoid the
anonymous struct extension, adjust everywhere.
* include/ext/rc_string_base.h (__rc_string_base<>::_S_empty_rep()):
Just use a static member.
(__rc_string_base<>::__rc_string_base(), _S_construct): Adjust.
* include/ext/rc_string_base.h (__rc_string_base<>::_Rep): Use anonymous
union together with _CharT to fix alignment issues, rebind to _Rep and
rename _Raw_alloc to _Rep_alloc_type.
(__rc_string_base<>::_Rep::_S_create, _M_destroy): Adjust consistently.
* include/ext/vstring_util.h (__is_null_p): Move inside struct
__vstring_utility as static _S_is_null_pointer.
* include/ext/sso_string.h
(__sso_string_base<>::_M_construct(std::forward_iterator_tag): Adjust.
* include/ext/rc_string_base.h
(__rc_string_base<>::_S_construct(std::forward_iterator_tag): Likewise.
Implement Option 3 of DR 431 for ext/vstring - both available bases.
* include/bits/cpp_type_traits.h (struct __is_empty): Add.
* include/ext/vstring.h (__versa_string<>::swap): Delegate to
this->_M_swap.
* include/ext/vstring.tcc (__versa_string<>::swap): Remove.
* include/ext/vstring_util.h (struct __vstring_utility<>): Add struct
_Alloc_hider<>, augmented of allocator swapping facility, specialized
to nop for empty allocators.
* include/ext/rc_string_base.h (__rc_string_base<>::_M_swap): Use it.
(__rc_string_base<>::_M_is_leaked, _M_set_sharable): Change to private.
* include/ext/sso_string_base.h (__sso_string_base<>::_M_swap):
Likewise.
(__sso_string_base<>::_M_is_leaked, _M_set_sharable): Remove, unused.
* include/ext/rc_string_base.h (__rc_string_base<>::_M_data(_CharT*):
Return void.
* include/ext/sso_string_base.h (__sso_string_base<>::_M_data(_CharT*):
Likewise.
2005-11-17 Geoffrey Keating <geoffk@apple.com>
* config/os/bsd/darwin/ppc-extra.ver: New.
......
......@@ -364,6 +364,26 @@ namespace std
};
};
//
// A stripped-down version of std::tr1::is_empty
//
template<typename _Tp>
struct __is_empty
{
private:
template<typename>
struct __first { };
template<typename _Up>
struct __second
: public _Up { };
public:
enum
{
__value = sizeof(__first<_Tp>) == sizeof(__second<_Tp>)
};
};
} // namespace std
#endif //_CPP_TYPE_TRAITS_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"));
......
......@@ -1214,7 +1214,8 @@ namespace __gnu_cxx
* time.
*/
void
swap(__versa_string& __s);
swap(__versa_string& __s)
{ this->_M_swap(__s); }
// String operations:
/**
......
......@@ -222,30 +222,6 @@ namespace __gnu_cxx
template <typename, typename, typename> class _Base>
void
__versa_string<_CharT, _Traits, _Alloc, _Base>::
swap(__versa_string& __s)
{
if (this->_M_is_leaked())
this->_M_set_sharable();
if (__s._M_is_leaked())
__s._M_set_sharable();
if (this->get_allocator() == __s.get_allocator())
this->_M_swap(__s);
// The code below can usually be optimized away.
else
{
const __versa_string __tmp1(_M_ibegin(), _M_iend(),
__s.get_allocator());
const __versa_string __tmp2(__s._M_ibegin(), __s._M_iend(),
this->get_allocator());
*this = __tmp2;
__s = __tmp1;
}
}
template<typename _CharT, typename _Traits, typename _Alloc,
template <typename, typename, typename> class _Base>
void
__versa_string<_CharT, _Traits, _Alloc, _Base>::
resize(size_type __n, _CharT __c)
{
const size_type __size = this->size();
......
// Versatile string utilities -*- C++ -*-
// Versatile string utility -*- C++ -*-
// Copyright (C) 2005 Free Software Foundation, Inc.
//
......@@ -47,16 +47,6 @@
namespace __gnu_cxx
{
template<typename _Type>
inline bool
__is_null_p(_Type* __ptr)
{ return __ptr == 0; }
template<typename _Type>
inline bool
__is_null_p(_Type)
{ return false; }
template<typename _CharT, typename _Traits, typename _Alloc>
struct __vstring_utility
{
......@@ -92,6 +82,53 @@ namespace __gnu_cxx
__rc_string_base> >
__const_rc_iterator;
// NB: When the allocator is empty, deriving from it saves space
// (http://www.cantrip.org/emptyopt.html). We do that anyway for
// consistency.
template<typename _Alloc1, bool = std::__is_empty<_Alloc1>::__value>
struct _Alloc_hider
: public _Alloc1
{
_Alloc_hider(const _Alloc1& __a, _CharT* __ptr)
: _Alloc1(__a), _M_p(__ptr) { }
void
_M_alloc_swap(_Alloc_hider& __ah)
{
// Implement Option 3 of DR 431 (see N1599).
// Precondition: swappable allocators.
_Alloc1& __this = static_cast<_Alloc1&>(*this);
_Alloc1& __that = static_cast<_Alloc1&>(__ah);
if (__this != __that)
swap(__this, __that);
}
_CharT* _M_p; // The actual data.
};
template<typename _Alloc1>
struct _Alloc_hider<_Alloc1, true>
: public _Alloc1
{
_Alloc_hider(const _Alloc1& __a, _CharT* __ptr)
: _Alloc1(__a), _M_p(__ptr) { }
void _M_alloc_swap(_Alloc_hider&) { }
_CharT* _M_p; // The actual data.
};
// For use in _M_construct (_S_construct) forward_iterator_tag.
template<typename _Type>
static bool
_S_is_null_pointer(_Type* __ptr)
{ return __ptr == 0; }
template<typename _Type>
static bool
_S_is_null_pointer(_Type)
{ return false; }
// When __n = 1 way faster than the general multichar
// traits_type::copy/move/assign.
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment