From c531371e87f6220c177a57d9a34e065cb3dc701d Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 4 May 2007 15:06:46 +0000 Subject: [PATCH] stl_construct.h (_Destroy(_ForwardIterator, _ForwardIterator __last, _Allocator)): Change the last parameter to _Allocator&. 2007-05-04 Paolo Carlini * include/bits/stl_construct.h (_Destroy(_ForwardIterator, _ForwardIterator __last, _Allocator)): Change the last parameter to _Allocator&. * include/bits/stl_uninitialized.h (__uninitialized_copy_a, __uninitialized_fill_a, __uninitialized_fill_n_a, __uninitialized_fill_copy, __uninitialized_copy_fill, __uninitialized_copy_copy): Likewise. * include/ext/rope: Adjust everywhere. * include/ext/ropeimpl.h: Likewise. From-SVN: r124427 --- libstdc++-v3/ChangeLog | 12 +++ libstdc++-v3/include/bits/stl_construct.h | 4 +- libstdc++-v3/include/bits/stl_uninitialized.h | 23 ++---- libstdc++-v3/include/ext/rope | 82 +++++++++++++------ libstdc++-v3/include/ext/ropeimpl.h | 50 +++++------ 5 files changed, 106 insertions(+), 65 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 48a0494cb5b..0f5b58b2afb 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2007-05-04 Paolo Carlini + + * include/bits/stl_construct.h (_Destroy(_ForwardIterator, + _ForwardIterator __last, _Allocator)): Change the last parameter + to _Allocator&. + * include/bits/stl_uninitialized.h (__uninitialized_copy_a, + __uninitialized_fill_a, __uninitialized_fill_n_a, + __uninitialized_fill_copy, __uninitialized_copy_fill, + __uninitialized_copy_copy): Likewise. + * include/ext/rope: Adjust everywhere. + * include/ext/ropeimpl.h: Likewise. + 2007-05-03 Benjamin Kosnik * include/std/type_traits (enable_if): New. diff --git a/libstdc++-v3/include/bits/stl_construct.h b/libstdc++-v3/include/bits/stl_construct.h index d80ade782f0..188efa92781 100644 --- a/libstdc++-v3/include/bits/stl_construct.h +++ b/libstdc++-v3/include/bits/stl_construct.h @@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template void _Destroy(_ForwardIterator __first, _ForwardIterator __last, - _Allocator __alloc) + _Allocator& __alloc) { for (; __first != __last; ++__first) __alloc.destroy(&*__first); @@ -146,7 +146,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last, - allocator<_Tp>) + allocator<_Tp>&) { _Destroy(__first, __last); } diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h b/libstdc++-v3/include/bits/stl_uninitialized.h index c460a56d021..8b5548e213f 100644 --- a/libstdc++-v3/include/bits/stl_uninitialized.h +++ b/libstdc++-v3/include/bits/stl_uninitialized.h @@ -198,8 +198,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) typename _Allocator> _ForwardIterator __uninitialized_copy_a(_InputIterator __first, _InputIterator __last, - _ForwardIterator __result, - _Allocator __alloc) + _ForwardIterator __result, _Allocator& __alloc) { _ForwardIterator __cur = __result; try @@ -218,14 +217,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template inline _ForwardIterator __uninitialized_copy_a(_InputIterator __first, _InputIterator __last, - _ForwardIterator __result, - allocator<_Tp>) + _ForwardIterator __result, allocator<_Tp>&) { return std::uninitialized_copy(__first, __last, __result); } template void __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __x, _Allocator __alloc) + const _Tp& __x, _Allocator& __alloc) { _ForwardIterator __cur = __first; try @@ -243,15 +241,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template inline void __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __x, allocator<_Tp2>) + const _Tp& __x, allocator<_Tp2>&) { std::uninitialized_fill(__first, __last, __x); } template void __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n, - const _Tp& __x, - _Allocator __alloc) + const _Tp& __x, _Allocator& __alloc) { _ForwardIterator __cur = __first; try @@ -270,8 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) typename _Tp2> inline void __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n, - const _Tp& __x, - allocator<_Tp2>) + const _Tp& __x, allocator<_Tp2>&) { std::uninitialized_fill_n(__first, __n, __x); } @@ -292,7 +288,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _InputIterator2 __first2, _InputIterator2 __last2, _ForwardIterator __result, - _Allocator __alloc) + _Allocator& __alloc) { _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1, __result, @@ -316,8 +312,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) inline _ForwardIterator __uninitialized_fill_copy(_ForwardIterator __result, _ForwardIterator __mid, const _Tp& __x, _InputIterator __first, - _InputIterator __last, - _Allocator __alloc) + _InputIterator __last, _Allocator& __alloc) { std::__uninitialized_fill_a(__result, __mid, __x, __alloc); try @@ -340,7 +335,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __uninitialized_copy_fill(_InputIterator __first1, _InputIterator __last1, _ForwardIterator __first2, _ForwardIterator __last2, const _Tp& __x, - _Allocator __alloc) + _Allocator& __alloc) { _ForwardIterator __mid2 = std::__uninitialized_copy_a(__first1, __last1, __first2, diff --git a/libstdc++-v3/include/ext/rope b/libstdc++-v3/include/ext/rope index 0bc371cd116..e0f0aa39036 100644 --- a/libstdc++-v3/include/ext/rope +++ b/libstdc++-v3/include/ext/rope @@ -533,6 +533,14 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) get_allocator() const { return *static_cast(this); } + allocator_type& + _M_get_allocator() + { return *static_cast<_Alloc*>(this); } + + const allocator_type& + _M_get_allocator() const + { return *static_cast(this); } + _Rope_rep_base(size_t __size, const allocator_type&) : _M_size(__size) { } @@ -572,9 +580,10 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) allocator_type; using _Rope_rep_base<_CharT, _Alloc>::get_allocator; + using _Rope_rep_base<_CharT, _Alloc>::_M_get_allocator; _Rope_RopeRep(__detail::_Tag __t, int __d, bool __b, size_t __size, - allocator_type __a) + const allocator_type& __a) : _Rope_rep_base<_CharT, _Alloc>(__size, __a), #ifndef __GC _Refcount_Base(1), @@ -595,7 +604,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) #endif static void _S_free_string(__GC_CONST _CharT*, size_t __len, - allocator_type __a); + allocator_type& __a); #define __STL_FREE_STRING(__s, __l, __a) _S_free_string(__s, __l, __a); // Deallocate data section of a leaf. // This shouldn't be a member function. @@ -689,7 +698,7 @@ protected: allocator_type; _Rope_RopeLeaf(__GC_CONST _CharT* __d, size_t __size, - allocator_type __a) + const allocator_type& __a) : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_leaf, 0, true, __size, __a), _M_data(__d) { @@ -708,7 +717,7 @@ protected: if (_M_data != this->_M_c_string) this->_M_free_c_string(); - __STL_FREE_STRING(_M_data, this->_M_size, this->get_allocator()); + __STL_FREE_STRING(_M_data, this->_M_size, this->_M_get_allocator()); } #endif protected: @@ -731,7 +740,7 @@ protected: _Rope_RopeConcatenation(_Rope_RopeRep<_CharT, _Alloc>* __l, _Rope_RopeRep<_CharT, _Alloc>* __r, - allocator_type __a) + const allocator_type& __a) : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_concat, std::max(__l->_M_depth, __r->_M_depth) + 1, @@ -779,7 +788,7 @@ protected: allocator_type; _Rope_RopeFunction(char_producer<_CharT>* __f, size_t __size, - bool __d, allocator_type __a) + bool __d, const allocator_type& __a) : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_function, 0, true, __size, __a) , _M_fn(__f) #ifndef __GC @@ -856,7 +865,7 @@ protected: allocator_type; _Rope_RopeSubstring(_Rope_RopeRep<_CharT, _Alloc>* __b, size_t __s, - size_t __l, allocator_type __a) + size_t __l, const allocator_type& __a) : _Rope_RopeFunction<_CharT, _Alloc>(this, __l, false, __a), char_producer<_CharT>(), _M_base(__b), _M_start(__s) { @@ -1444,6 +1453,14 @@ protected: get_allocator() const { return *static_cast(this); } + allocator_type& + _M_get_allocator() + { return *static_cast<_Alloc*>(this); } + + const allocator_type& + _M_get_allocator() const + { return *static_cast(this); } + typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep; // The one in _Base may not be visible due to template rules. @@ -1504,6 +1521,7 @@ protected: typedef typename _Base::allocator_type allocator_type; using _Base::_M_tree_ptr; using _Base::get_allocator; + using _Base::_M_get_allocator; typedef __GC_CONST _CharT* _Cstrptr; static _CharT _S_empty_c_str[1]; @@ -1614,7 +1632,7 @@ protected: // Takes ownership of s instead of copying. static _RopeLeaf* _S_new_RopeLeaf(__GC_CONST _CharT *__s, - size_t __size, allocator_type __a) + size_t __size, allocator_type& __a) { _RopeLeaf* __space = typename _Base::_LAlloc(__a).allocate(1); return new(__space) _RopeLeaf(__s, __size, __a); @@ -1622,7 +1640,7 @@ protected: static _RopeConcatenation* _S_new_RopeConcatenation(_RopeRep* __left, _RopeRep* __right, - allocator_type __a) + allocator_type& __a) { _RopeConcatenation* __space = typename _Base::_CAlloc(__a).allocate(1); return new(__space) _RopeConcatenation(__left, __right, __a); @@ -1630,7 +1648,7 @@ protected: static _RopeFunction* _S_new_RopeFunction(char_producer<_CharT>* __f, - size_t __size, bool __d, allocator_type __a) + size_t __size, bool __d, allocator_type& __a) { _RopeFunction* __space = typename _Base::_FAlloc(__a).allocate(1); return new(__space) _RopeFunction(__f, __size, __d, __a); @@ -1638,7 +1656,7 @@ protected: static _RopeSubstring* _S_new_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s, - size_t __l, allocator_type __a) + size_t __l, allocator_type& __a) { _RopeSubstring* __space = typename _Base::_SAlloc(__a).allocate(1); return new(__space) _RopeSubstring(__b, __s, __l, __a); @@ -1646,7 +1664,7 @@ protected: static _RopeLeaf* _S_RopeLeaf_from_unowned_char_ptr(const _CharT *__s, - size_t __size, allocator_type __a) + size_t __size, allocator_type& __a) #define __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __size, __a) \ _S_RopeLeaf_from_unowned_char_ptr(__s, __size, __a) { @@ -1768,22 +1786,31 @@ protected: { return _S_compare(this->_M_tree_ptr, __y._M_tree_ptr); } rope(const _CharT* __s, const allocator_type& __a = allocator_type()) - : _Base(__STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _S_char_ptr_len(__s), - __a), __a) - { } + : _Base(__a) + { + this->_M_tree_ptr = + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _S_char_ptr_len(__s), + _M_get_allocator()); + } rope(const _CharT* __s, size_t __len, const allocator_type& __a = allocator_type()) - : _Base(__STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __len, __a), __a) - { } + : _Base(__a) + { + this->_M_tree_ptr = + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __len, _M_get_allocator()); + } // Should perhaps be templatized with respect to the iterator type // and use Sequence_buffer. (It should perhaps use sequence_buffer // even now.) - rope(const _CharT *__s, const _CharT *__e, + rope(const _CharT* __s, const _CharT* __e, const allocator_type& __a = allocator_type()) - : _Base(__STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __e - __s, __a), __a) - { } + : _Base(__a) + { + this->_M_tree_ptr = + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __e - __s, _M_get_allocator()); + } rope(const const_iterator& __s, const const_iterator& __e, const allocator_type& __a = allocator_type()) @@ -1802,12 +1829,15 @@ protected: { _CharT* __buf = this->_Data_allocate(_S_rounded_up_size(1)); - get_allocator().construct(__buf, __c); + _M_get_allocator().construct(__buf, __c); try - { this->_M_tree_ptr = _S_new_RopeLeaf(__buf, 1, __a); } + { + this->_M_tree_ptr = _S_new_RopeLeaf(__buf, 1, + _M_get_allocator()); + } catch(...) { - _RopeRep::__STL_FREE_STRING(__buf, 1, __a); + _RopeRep::__STL_FREE_STRING(__buf, 1, _M_get_allocator()); __throw_exception_again; } } @@ -1878,7 +1908,7 @@ protected: { _RopeRep* __old = this->_M_tree_ptr; _RopeRep* __left = - __STL_ROPE_FROM_UNOWNED_CHAR_PTR(&__x, 1, this->get_allocator()); + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(&__x, 1, _M_get_allocator()); try { this->_M_tree_ptr = _S_concat(__left, this->_M_tree_ptr); @@ -1916,7 +1946,7 @@ protected: void copy(_CharT* __buffer) const { - _Destroy(__buffer, __buffer + size(), get_allocator()); + _Destroy(__buffer, __buffer + size(), _M_get_allocator()); _S_flatten(this->_M_tree_ptr, __buffer); } @@ -1931,7 +1961,7 @@ protected: size_t __size = size(); size_t __len = (__pos + __n > __size? __size - __pos : __n); - _Destroy(__buffer, __buffer + __len, get_allocator()); + _Destroy(__buffer, __buffer + __len, _M_get_allocator()); _S_flatten(this->_M_tree_ptr, __pos, __len, __buffer); return __len; } diff --git a/libstdc++-v3/include/ext/ropeimpl.h b/libstdc++-v3/include/ext/ropeimpl.h index bbe6b9970bf..95dd8c2f722 100644 --- a/libstdc++-v3/include/ext/ropeimpl.h +++ b/libstdc++-v3/include/ext/ropeimpl.h @@ -1,6 +1,6 @@ // SGI's rope class implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -347,7 +347,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) if (0 != __cstr) { size_t __size = this->_M_size + 1; - _Destroy(__cstr, __cstr + __size, get_allocator()); + _Destroy(__cstr, __cstr + __size, _M_get_allocator()); this->_Data_deallocate(__cstr, __size); } } @@ -355,7 +355,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) template inline void _Rope_RopeRep<_CharT, _Alloc>:: - _S_free_string(_CharT* __s, size_t __n, allocator_type __a) + _S_free_string(_CharT* __s, size_t __n, allocator_type& __a) { if (!_S_is_basic_char_type((_CharT*)0)) _Destroy(__s, __s + __n, __a); @@ -442,12 +442,12 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) try { __result = _S_new_RopeLeaf(__new_data, __old_len + __len, - __r->get_allocator()); + __r->_M_get_allocator()); } catch(...) { _RopeRep::__STL_FREE_STRING(__new_data, __old_len + __len, - __r->get_allocator()); + __r->_M_get_allocator()); __throw_exception_again; } return __result; @@ -498,7 +498,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) { _RopeConcatenation* __result = _S_new_RopeConcatenation(__left, __right, __left-> - get_allocator()); + _M_get_allocator()); size_t __depth = __result->_M_depth; if (__depth > 20 @@ -540,7 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) } if (0 == __r) return __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, - __r->get_allocator()); + __r->_M_get_allocator()); if (__r->_M_tag == __detail::_S_leaf && __r->_M_size + __slen <= size_t(_S_copy_max)) { @@ -570,7 +570,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) } } _RopeRep* __nright = - __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, __r->get_allocator()); + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, __r->_M_get_allocator()); try { __r->_M_ref_nonnil(); @@ -594,7 +594,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) _RopeRep* __result; if (0 == __r) return __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, - __r->get_allocator()); + __r->_M_get_allocator()); size_t __count = __r->_M_ref_count; size_t __orig_size = __r->_M_size; if (__count > 1) @@ -636,7 +636,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) } } _RopeRep* __right = - __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, __r->get_allocator()); + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, __r->_M_get_allocator()); __r->_M_ref_nonnil(); try { __result = _S_tree_concat(__r, __right); } @@ -775,14 +775,14 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) #ifdef __GC const _CharT* __section = __l->_M_data + __start; __result = _S_new_RopeLeaf(__section, __result_len, - __base->get_allocator()); + __base->_M_get_allocator()); __result->_M_c_string = 0; // Not eos terminated. #else // We should sometimes create substring node instead. __result = __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__l->_M_data + __start, __result_len, __base-> - get_allocator()); + _M_get_allocator()); #endif return __result; } @@ -800,7 +800,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) _S_new_RopeSubstring(__old->_M_base, __start + __old->_M_start, __adj_endp1 - __start, - __base->get_allocator()); + __base->_M_get_allocator()); return __result; } // *** else fall through: *** @@ -823,19 +823,19 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) catch(...) { _RopeRep::__STL_FREE_STRING(__section, __result_len, - __base->get_allocator()); + __base->_M_get_allocator()); __throw_exception_again; } _S_cond_store_eos(__section[__result_len]); return _S_new_RopeLeaf(__section, __result_len, - __base->get_allocator()); + __base->_M_get_allocator()); } } lazy: { // Create substring node. return _S_new_RopeSubstring(__base, __start, __adj_endp1 - __start, - __base->get_allocator()); + __base->_M_get_allocator()); } } @@ -1550,13 +1550,15 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) { __rest_buffer = this->_Data_allocate(_S_rounded_up_size(__rest)); __uninitialized_fill_n_a(__rest_buffer, __rest, __c, - get_allocator()); + _M_get_allocator()); _S_cond_store_eos(__rest_buffer[__rest]); try - { __remainder = _S_new_RopeLeaf(__rest_buffer, __rest, __a); } + { __remainder = _S_new_RopeLeaf(__rest_buffer, __rest, + _M_get_allocator()); } catch(...) { - _RopeRep::__STL_FREE_STRING(__rest_buffer, __rest, __a); + _RopeRep::__STL_FREE_STRING(__rest_buffer, __rest, + _M_get_allocator()); __throw_exception_again; } } @@ -1568,17 +1570,19 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) _RopeLeaf* __base_leaf; rope __base_rope; __uninitialized_fill_n_a(__base_buffer, __exponentiate_threshold, __c, - get_allocator()); + _M_get_allocator()); _S_cond_store_eos(__base_buffer[__exponentiate_threshold]); try { __base_leaf = _S_new_RopeLeaf(__base_buffer, - __exponentiate_threshold, __a); + __exponentiate_threshold, + _M_get_allocator()); } catch(...) { _RopeRep::__STL_FREE_STRING(__base_buffer, - __exponentiate_threshold, __a); + __exponentiate_threshold, + _M_get_allocator()); __throw_exception_again; } __base_rope._M_tree_ptr = __base_leaf; @@ -1646,7 +1650,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) __result[__s] = _S_eos((_CharT*)0); this->_M_tree_ptr->_M_unref_nonnil(); this->_M_tree_ptr = _S_new_RopeLeaf(__result, __s, - this->get_allocator()); + this->_M_get_allocator()); return(__result); } -- 2.30.2