diff options
author | Paolo Carlini <pcarlini@suse.de> | 2005-06-12 20:43:32 +0000 |
---|---|---|
committer | Paolo Carlini <pcarlini@suse.de> | 2005-06-12 20:43:32 +0000 |
commit | b41fe46601b4986ba4ebf30bae5465ab5ca8289c (patch) | |
tree | ae48076f1c243f1dc56271c82b3480ff4f6a3c28 | |
parent | fa156d9b2f5b05bb74cfce933ad218d50c074702 (diff) |
2005-06-12 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.h (reserve): Forward to
_M_reserve.
(assign(const basic_string&)): Likewise to _M_assign.
* include/bits/basic_string.tcc (reserve,
assign(const basic_string&)): Remove.
* include/ext/rc_string.h (_M_reserve): Tweak consistently.
* include/ext/sso_string.h (_M_reserve): Likewise.
* include/ext/sso_string.h (_M_dispose): New, check
_M_is_local and forward to _M_destroy.
(_M_destroy): Adjust; adjust all callers to use _M_dispose.
(_M_reserve): Use _M_destroy.
* include/ext/sso_string.h: Rename _S_construct ->
_M_construct.
* src/sso_string-inst.cc: Likewise.
* src/allocator-inst.cc: Add instantiation for size_t.
* src/bitmap_allocator.cc: Likewise.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/libstdcxx_so_7-branch@100863 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libstdc++-v3/ChangeLog.libstdcxx_so_7-branch | 22 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.h | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.tcc | 23 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/rc_string.h | 15 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/sso_string.h | 118 | ||||
-rw-r--r-- | libstdc++-v3/src/allocator-inst.cc | 4 | ||||
-rw-r--r-- | libstdc++-v3/src/bitmap_allocator.cc | 1 | ||||
-rw-r--r-- | libstdc++-v3/src/sso_string-inst.cc | 6 |
8 files changed, 111 insertions, 87 deletions
diff --git a/libstdc++-v3/ChangeLog.libstdcxx_so_7-branch b/libstdc++-v3/ChangeLog.libstdcxx_so_7-branch index 8db7c4619bd..dfdba2dd43e 100644 --- a/libstdc++-v3/ChangeLog.libstdcxx_so_7-branch +++ b/libstdc++-v3/ChangeLog.libstdcxx_so_7-branch @@ -1,3 +1,25 @@ +2005-06-12 Paolo Carlini <pcarlini@suse.de> + + * include/bits/basic_string.h (reserve): Forward to + _M_reserve. + (assign(const basic_string&)): Likewise to _M_assign. + * include/bits/basic_string.tcc (reserve, + assign(const basic_string&)): Remove. + * include/ext/rc_string.h (_M_reserve): Tweak consistently. + * include/ext/sso_string.h (_M_reserve): Likewise. + + * include/ext/sso_string.h (_M_dispose): New, check + _M_is_local and forward to _M_destroy. + (_M_destroy): Adjust; adjust all callers to use _M_dispose. + (_M_reserve): Use _M_destroy. + + * include/ext/sso_string.h: Rename _S_construct -> + _M_construct. + * src/sso_string-inst.cc: Likewise. + + * src/allocator-inst.cc: Add instantiation for size_t. + * src/bitmap_allocator.cc: Likewise. + 2005-06-11 Paolo Carlini <pcarlini@suse.de> * include/ext/sso_string.h (__sso_string::_Alloc_hider): Adjust diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index f36612df1dc..eb44dff857c 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -414,7 +414,8 @@ namespace std * data. */ void - reserve(size_type __res_arg = 0); + reserve(size_type __res_arg = 0) + { this->_M_reserve(__res_arg); } /** * Erases the string, making it empty. @@ -623,7 +624,11 @@ namespace std * @return Reference to this string. */ basic_string& - assign(const basic_string& __str); + assign(const basic_string& __str) + { + this->_M_assign(__str); + return *this; + } /** * @brief Set value to a substring of a string. diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 967a88cea5c..a924bf82fd3 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -54,15 +54,6 @@ namespace std template<typename _CharT, typename _Traits, typename _Alloc> basic_string<_CharT, _Traits, _Alloc>& basic_string<_CharT, _Traits, _Alloc>:: - assign(const basic_string& __str) - { - this->_M_assign(__str); - return *this; - } - - template<typename _CharT, typename _Traits, typename _Alloc> - basic_string<_CharT, _Traits, _Alloc>& - basic_string<_CharT, _Traits, _Alloc>:: assign(const _CharT* __s, size_type __n) { __glibcxx_requires_string_len(__s, __n); @@ -229,20 +220,6 @@ namespace std template<typename _CharT, typename _Traits, typename _Alloc> void basic_string<_CharT, _Traits, _Alloc>:: - reserve(size_type __res) - { - if (__res != this->capacity() || this->_M_is_shared()) - { - // Make sure we don't shrink below the current size - if (__res < this->size()) - __res = this->size(); - this->_M_reserve(__res); - } - } - - template<typename _CharT, typename _Traits, typename _Alloc> - void - basic_string<_CharT, _Traits, _Alloc>:: swap(basic_string& __s) { if (this->_M_is_leaked()) diff --git a/libstdc++-v3/include/ext/rc_string.h b/libstdc++-v3/include/ext/rc_string.h index 0ece46583c3..7857330eacf 100644 --- a/libstdc++-v3/include/ext/rc_string.h +++ b/libstdc++-v3/include/ext/rc_string.h @@ -618,10 +618,17 @@ namespace __gnu_cxx __rc_string<_CharT, _Traits, _Alloc>:: _M_reserve(size_type __res) { - const allocator_type __a = _M_get_allocator(); - _CharT* __tmp = _M_rep()->_M_clone(__a, __res - _M_length()); - _M_dispose(__a); - _M_data(__tmp); + if (__res != _M_capacity() || _M_is_shared()) + { + // Make sure we don't shrink below the current size. + if (__res < _M_length()) + __res = _M_length(); + + const allocator_type __a = _M_get_allocator(); + _CharT* __tmp = _M_rep()->_M_clone(__a, __res - _M_length()); + _M_dispose(__a); + _M_data(__tmp); + } } template<typename _CharT, typename _Traits, typename _Alloc> diff --git a/libstdc++-v3/include/ext/sso_string.h b/libstdc++-v3/include/ext/sso_string.h index 9261a8590c9..0bd6274981a 100644 --- a/libstdc++-v3/include/ext/sso_string.h +++ b/libstdc++-v3/include/ext/sso_string.h @@ -117,7 +117,14 @@ namespace __gnu_cxx _S_create(size_type&, size_type, const _Alloc&); void - _M_destroy(const _Alloc&) throw(); + _M_dispose(const _Alloc& __a) throw() + { + if (!_M_is_local()) + _M_destroy(__a, _M_allocated_capacity + 1); + } + + void + _M_destroy(const _Alloc&, size_type) throw(); // Use empty-base optimization: http://www.cantrip.org/emptyopt.html struct _Alloc_hider : _Alloc @@ -128,7 +135,7 @@ namespace __gnu_cxx _CharT* _M_p; // The actual data. }; - // Data Member (private): + // Data Members (private): _Alloc_hider _M_dataplus; size_type _M_string_length; @@ -152,43 +159,43 @@ namespace __gnu_cxx // requires special behaviour if _InIter is an integral type template<class _InIterator> void - _S_construct_aux(_InIterator __beg, _InIterator __end, + _M_construct_aux(_InIterator __beg, _InIterator __end, const _Alloc& __a, __false_type) { typedef typename iterator_traits<_InIterator>::iterator_category _Tag; - _S_construct(__beg, __end, __a, _Tag()); + _M_construct(__beg, __end, __a, _Tag()); } template<class _InIterator> void - _S_construct_aux(_InIterator __beg, _InIterator __end, + _M_construct_aux(_InIterator __beg, _InIterator __end, const _Alloc& __a, __true_type) - { _S_construct(static_cast<size_type>(__beg), + { _M_construct(static_cast<size_type>(__beg), static_cast<value_type>(__end), __a); } template<class _InIterator> void - _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a) + _M_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a) { typedef typename std::__is_integer<_InIterator>::__type _Integral; - _S_construct_aux(__beg, __end, __a, _Integral()); + _M_construct_aux(__beg, __end, __a, _Integral()); } // For Input Iterators, used in istreambuf_iterators, etc. template<class _InIterator> void - _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, + _M_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, std::input_iterator_tag); // For forward_iterators up to random_access_iterators, used for // string::iterator, _CharT*, etc. template<class _FwdIterator> void - _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a, + _M_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a, std::forward_iterator_tag); void - _S_construct(size_type __req, _CharT __c, const _Alloc& __a); + _M_construct(size_type __req, _CharT __c, const _Alloc& __a); public: _CharT* @@ -247,7 +254,7 @@ namespace __gnu_cxx const _Alloc& __a); ~__sso_string() - { _M_destroy(_M_get_allocator()); } + { _M_dispose(_M_get_allocator()); } allocator_type _M_get_allocator() const @@ -269,6 +276,12 @@ namespace __gnu_cxx template<typename _CharT, typename _Traits, typename _Alloc> void __sso_string<_CharT, _Traits, _Alloc>:: + _M_destroy(const _Alloc& __a, size_type __size) throw() + { _CharT_alloc_type(__a).deallocate(_M_data(), __size); } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __sso_string<_CharT, _Traits, _Alloc>:: _M_swap(__sso_string& __rcs) { const bool __local = _M_is_local(); @@ -357,39 +370,30 @@ namespace __gnu_cxx } template<typename _CharT, typename _Traits, typename _Alloc> - void - __sso_string<_CharT, _Traits, _Alloc>:: - _M_destroy(const _Alloc& __a) throw () - { - if (!_M_is_local()) - _CharT_alloc_type(__a).deallocate(_M_data(), _M_allocated_capacity + 1); - } - - template<typename _CharT, typename _Traits, typename _Alloc> __sso_string<_CharT, _Traits, _Alloc>:: __sso_string(const _Alloc& __a) : _M_dataplus(__a, _M_local_data) - { _S_construct(size_type(), _CharT(), __a); } + { _M_construct(size_type(), _CharT(), __a); } template<typename _CharT, typename _Traits, typename _Alloc> __sso_string<_CharT, _Traits, _Alloc>:: __sso_string(const __sso_string& __rcs) : _M_dataplus(__rcs._M_get_allocator(), _M_local_data) - { _S_construct(__rcs._M_data(), __rcs._M_data() + __rcs._M_length(), + { _M_construct(__rcs._M_data(), __rcs._M_data() + __rcs._M_length(), __rcs._M_get_allocator()); } template<typename _CharT, typename _Traits, typename _Alloc> __sso_string<_CharT, _Traits, _Alloc>:: __sso_string(size_type __n, _CharT __c, const _Alloc& __a) : _M_dataplus(__a, _M_local_data) - { _S_construct(__n, __c, __a); } + { _M_construct(__n, __c, __a); } template<typename _CharT, typename _Traits, typename _Alloc> template<typename _InputIterator> __sso_string<_CharT, _Traits, _Alloc>:: __sso_string(_InputIterator __beg, _InputIterator __end, const _Alloc& __a) : _M_dataplus(__a, _M_local_data) - { _S_construct(__beg, __end, __a); } + { _M_construct(__beg, __end, __a); } // NB: This is the special case for Input Iterators, used in // istreambuf_iterators, etc. @@ -399,7 +403,7 @@ namespace __gnu_cxx template<typename _InIterator> void __sso_string<_CharT, _Traits, _Alloc>:: - _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, + _M_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, std::input_iterator_tag) { // Avoid reallocation for common case. @@ -422,7 +426,7 @@ namespace __gnu_cxx __capacity = __len + 1; _CharT* __another = _S_create(__capacity, __len, __a); _S_copy(__another, _M_data(), __len); - _M_destroy(__a); + _M_dispose(__a); _M_data(__another); _M_capacity(__capacity); } @@ -432,7 +436,7 @@ namespace __gnu_cxx } catch(...) { - _M_destroy(__a); + _M_dispose(__a); __throw_exception_again; } @@ -443,7 +447,7 @@ namespace __gnu_cxx template <typename _InIterator> void __sso_string<_CharT, _Traits, _Alloc>:: - _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, + _M_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, std::forward_iterator_tag) { // NB: Not required, but considered best practice. @@ -464,7 +468,7 @@ namespace __gnu_cxx { _S_copy_chars(_M_data(), __beg, __end); } catch(...) { - _M_destroy(__a); + _M_dispose(__a); __throw_exception_again; } @@ -474,7 +478,7 @@ namespace __gnu_cxx template<typename _CharT, typename _Traits, typename _Alloc> void __sso_string<_CharT, _Traits, _Alloc>:: - _S_construct(size_type __n, _CharT __c, const _Alloc& __a) + _M_construct(size_type __n, _CharT __c, const _Alloc& __a) { if (__n > size_type(_S_local_capacity)) { @@ -502,7 +506,7 @@ namespace __gnu_cxx if (__size > size_type(_S_local_capacity)) __tmp = _S_create(__size, size_type(0), __a); - _M_destroy(__a); + _M_dispose(__a); _M_data(__tmp); if (__size) @@ -521,29 +525,35 @@ namespace __gnu_cxx _M_reserve(size_type __res) { const size_type __capacity = _M_capacity(); - const allocator_type __a = _M_get_allocator(); - - if (__res > __capacity - || __res > size_type(_S_local_capacity)) + if (__res != __capacity) { - _CharT* __tmp = _S_create(__res, __capacity, __a); - if (_M_length()) - _S_copy(__tmp, _M_data(), _M_length()); - _M_destroy(__a); - _M_data(__tmp); - _M_capacity(__res); - } - else if (!_M_is_local()) - { - const size_type __tmp_capacity = _M_allocated_capacity; - if (_M_length()) - _S_copy(_M_local_data, _M_data(), _M_length()); - // XXX - _CharT_alloc_type(__a).deallocate(_M_data(), __tmp_capacity + 1); - _M_data(_M_local_data); - } + const allocator_type __a = _M_get_allocator(); - _M_set_length(_M_length()); + // Make sure we don't shrink below the current size. + if (__res < _M_length()) + __res = _M_length(); + + if (__res > __capacity + || __res > size_type(_S_local_capacity)) + { + _CharT* __tmp = _S_create(__res, __capacity, __a); + if (_M_length()) + _S_copy(__tmp, _M_data(), _M_length()); + _M_dispose(__a); + _M_data(__tmp); + _M_capacity(__res); + } + else if (!_M_is_local()) + { + const size_type __tmp_capacity = _M_allocated_capacity; + if (_M_length()) + _S_copy(_M_local_data, _M_data(), _M_length()); + _M_destroy(__a, __tmp_capacity + 1); + _M_data(_M_local_data); + } + + _M_set_length(_M_length()); + } } template<typename _CharT, typename _Traits, typename _Alloc> @@ -568,7 +578,7 @@ namespace __gnu_cxx _S_copy(__r + __pos + __len2, _M_data() + __pos + __len1, __how_much); - _M_destroy(__a); + _M_dispose(__a); _M_data(__r); _M_capacity(__new_capacity); } diff --git a/libstdc++-v3/src/allocator-inst.cc b/libstdc++-v3/src/allocator-inst.cc index d25f488e4ca..d1e61561938 100644 --- a/libstdc++-v3/src/allocator-inst.cc +++ b/libstdc++-v3/src/allocator-inst.cc @@ -1,6 +1,7 @@ // Explicit instantiation file. -// Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005 +// Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -37,4 +38,5 @@ namespace std { template class allocator<char>; template class allocator<wchar_t>; + template class allocator<size_t>; } // namespace std diff --git a/libstdc++-v3/src/bitmap_allocator.cc b/libstdc++-v3/src/bitmap_allocator.cc index 4e42cced450..2be53511027 100644 --- a/libstdc++-v3/src/bitmap_allocator.cc +++ b/libstdc++-v3/src/bitmap_allocator.cc @@ -128,4 +128,5 @@ namespace __gnu_cxx // Instantiations. template class bitmap_allocator<char>; template class bitmap_allocator<wchar_t>; + template class bitmap_allocator<size_t>; } // namespace __gnu_cxx diff --git a/libstdc++-v3/src/sso_string-inst.cc b/libstdc++-v3/src/sso_string-inst.cc index 0a9538ca7de..08c59ae07ce 100644 --- a/libstdc++-v3/src/sso_string-inst.cc +++ b/libstdc++-v3/src/sso_string-inst.cc @@ -60,16 +60,16 @@ namespace __gnu_cxx template void - RS::_S_construct(RS::iterator, RS::iterator, + RS::_M_construct(RS::iterator, RS::iterator, const allocator<C>&, std::forward_iterator_tag); template void - RS::_S_construct(C*, C*, const allocator<C>&, + RS::_M_construct(C*, C*, const allocator<C>&, std::forward_iterator_tag); template void - RS::_S_construct(const C*, const C*, const allocator<C>&, + RS::_M_construct(const C*, const C*, const allocator<C>&, std::forward_iterator_tag); } // namespace __gnu_cxx |