diff options
author | Paolo Carlini <pcarlini@suse.de> | 2005-12-05 00:32:31 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2005-12-05 00:32:31 +0000 |
commit | cf8829194fb63dc0c25253934e1cff4bf4c7f6ca (patch) | |
tree | 92c651354a9a4c8882011f990f958ea570368aaf /libstdc++-v3/include/ext/rc_string_base.h | |
parent | 7343398692a7c9fbdeea485e51d34ef0a5be9c5b (diff) | |
download | gcc-cf8829194fb63dc0c25253934e1cff4bf4c7f6ca.zip gcc-cf8829194fb63dc0c25253934e1cff4bf4c7f6ca.tar.gz gcc-cf8829194fb63dc0c25253934e1cff4bf4c7f6ca.tar.bz2 |
vstring.h (__versa_string<>::operator+, [...]): Move out of line...
2005-12-04 Paolo Carlini <pcarlini@suse.de>
* include/ext/vstring.h (__versa_string<>::operator+, all
versions): Move out of line...
* include/ext/vstring.tcc (__versa_string<>::operator+): ...
here; consistently use reserve for the benefit of sso_string_base;
prefer push_back to single-char append when appropriate.
* include/ext/vstring.h (__versa_string<>::push_back): Don't
call _M_reserve, _M_mutate instead.
(reserve): Just forward to _M_reserve.
* include/ext/vstring.tcc (__versa_string<>::_M_reserve): Remove.
* include/ext/rc_string_base.h (__rc_string_base<>::_M_reserve): Also
do the initial checks (first on length, in case __res == capacity).
* include/ext/sso_string_base.h (__sso_string_base<>::_M_reserve:
Likewise; don't call _M_set_length unnecessarily.
2005-12-04 Paolo Carlini <pcarlini@suse.de>
* include/ext/vstring.h (__versa_string<>::_M_append): New.
(append(const __versa_string&), append(const __versa_string&,
size_type, size_type), append(const _CharT*, size_type),
append(const _CharT*)): Use it.
(append(size_type, _CharT)): Delegate to _M_replace_aux.
(assign(const __versa_string&, size_type, size_type),
assign(const _CharT*), replace(size_type, size_type,
const _CharT*, size_type)): Forward to _M_replace.
* include/ext/vstring.tcc (__versa_string<>::_M_append):
Define, core append functionality.
(_M_replace): Simplify, move __s == 0 case to _M_replace_aux.
(_M_replace_aux): Reorganize, don't call _M_replace.
2005-12-04 Paolo Carlini <pcarlini@suse.de>
* include/ext/vstring.tcc (__versa_string<>::_M_replace):
Perform _M_check_length at the beginning and remove it from ...
(replace, _M_replace_dispatch, _M_replace_aux, assign): ... here.
(assign): Now move inline.
(resize): Don't call _M_check_length redundantly, append does.
2005-12-04 Paolo Carlini <pcarlini@suse.de>
* include/ext/sso_string_base.h (__sso_string_base<>::_M_get_allocator):
Add non const version.
* include/ext/rc_string_base.h (__rc_string_base<>::_M_get_allocator):
Likewise.
* include/ext/sso_string_base.h (__sso_string_base<>::_M_erase): Add.
* include/ext/rc_string_base.h (__rc_string_base<>::_M_erase): Likewise.
(_M_leak_hard): Use it.
* include/ext/vstring.h (__versa_string<>::clear, erase, all
versions): Use it.
* include/ext/vstring.tcc (__versa_string<>::resize): Likewise.
* include/ext/vstring.h (__versa_string<>::_M_replace_safe):
Remove.
* include/ext/vstring.h (__versa_string<>::_M_replace): New, does
the in-place work or delegates to _M_mutate in case of reallocation.
* include/ext/vstring.tcc (__versa_string<>::_M_replace_safe):
Remove.
* include/ext/vstring.tcc (__versa_string<>::_M_replace): Define.
(assign, replace, _M_replace_dispatch, _M_replace_aux): Use it.
* include/ext/sso_string_base.h (__sso_string_base<>::_M_mutate):
Change to manage only reallocations.
* include/ext/rc_string_base.h (__rc_string_base<>::_M_mutate):
Likewise.
* include/ext/vstring.h (__versa_string<>::insert(size_type,
const __versa_string&), insert(size_type, const __versa_string&,
size_type, size_type), insert(size_type, const _CharT*, size_type),
insert(size_type, const _CharT*)): Delegate to replace.
* include/ext/vstring.h (__versa_string<>::reserve): Move out of
line.
* include/ext/vstring.tcc (__versa_string<>::reserve): Do the
checks and call _M_reserve.
* include/ext/vstring.h (__versa_string<>::append): Call _M_reserve
instead of reserve.
* include/ext/vstring.tcc (__versa_string<>::append, all versions):
Likewise.
* include/ext/sso_string_base.h (__sso_string_base<>::_M_reserve):
Adjust.
* include/ext/rc_string_base.h (__rc_string_base<>::_M_reserve):
Likewise.
From-SVN: r108034
Diffstat (limited to 'libstdc++-v3/include/ext/rc_string_base.h')
-rw-r--r-- | libstdc++-v3/include/ext/rc_string_base.h | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/libstdc++-v3/include/ext/rc_string_base.h b/libstdc++-v3/include/ext/rc_string_base.h index 8fb7531..9636a81 100644 --- a/libstdc++-v3/include/ext/rc_string_base.h +++ b/libstdc++-v3/include/ext/rc_string_base.h @@ -311,6 +311,10 @@ namespace __gnu_cxx ~__rc_string_base() { _M_dispose(); } + allocator_type& + _M_get_allocator() + { return _M_dataplus; } + const allocator_type& _M_get_allocator() const { return _M_dataplus; } @@ -325,7 +329,11 @@ namespace __gnu_cxx _M_reserve(size_type __res); void - _M_mutate(size_type __pos, size_type __len1, size_type __len2); + _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, + size_type __len2); + + void + _M_erase(size_type __pos, size_type __n); }; template<typename _CharT, typename _Traits, typename _Alloc> @@ -377,8 +385,8 @@ namespace __gnu_cxx // NB: Need an array of char_type[__capacity], plus a terminating // null char_type() element, plus enough for the _Rep data structure, - // plus sizeof(size_type) - 1 to upper round to a size multiple - // of sizeof(size_type). + // plus sizeof(_Rep) - 1 to upper round to a size multiple of + // sizeof(_Rep). // Whew. Seemingly so needy, yet so elemental. size_type __size = ((__capacity + 1) * sizeof(_CharT) + 2 * sizeof(_Rep) - 1); @@ -458,7 +466,7 @@ namespace __gnu_cxx _M_leak_hard() { if (_M_is_shared()) - _M_mutate(0, 0, 0); + _M_erase(0, 0); _M_set_leaked(); } @@ -490,7 +498,7 @@ namespace __gnu_cxx { while (__beg != __end) { - if (__len == __r->_M_capacity) + if (__len == __r->_M_info._M_capacity) { // Allocate more space. _Rep* __another = _Rep::_S_create(__len + 1, __len, __a); @@ -594,12 +602,12 @@ namespace __gnu_cxx __rc_string_base<_CharT, _Traits, _Alloc>:: _M_reserve(size_type __res) { + // Make sure we don't shrink below the current size. + if (__res < _M_length()) + __res = _M_length(); + if (__res != _M_capacity() || _M_is_shared()) { - // Make sure we don't shrink below the current size. - if (__res < _M_length()) - __res = _M_length(); - _CharT* __tmp = _M_rep()->_M_clone(_M_get_allocator(), __res - _M_length()); _M_dispose(); @@ -610,13 +618,35 @@ namespace __gnu_cxx template<typename _CharT, typename _Traits, typename _Alloc> void __rc_string_base<_CharT, _Traits, _Alloc>:: - _M_mutate(size_type __pos, size_type __len1, size_type __len2) + _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, + size_type __len2) { - const size_type __old_size = _M_length(); - const size_type __new_size = __old_size + __len2 - __len1; - const size_type __how_much = __old_size - __pos - __len1; + const size_type __how_much = _M_length() - __pos - __len1; + + _Rep* __r = _Rep::_S_create(_M_length() + __len2 - __len1, + _M_capacity(), _M_get_allocator()); - if (__new_size > _M_capacity() || _M_is_shared()) + if (__pos) + _S_copy(__r->_M_refdata(), _M_data(), __pos); + if (__s && __len2) + _S_copy(__r->_M_refdata() + __pos, __s, __len2); + if (__how_much) + _S_copy(__r->_M_refdata() + __pos + __len2, + _M_data() + __pos + __len1, __how_much); + + _M_dispose(); + _M_data(__r->_M_refdata()); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __rc_string_base<_CharT, _Traits, _Alloc>:: + _M_erase(size_type __pos, size_type __n) + { + const size_type __new_size = _M_length() - __n; + const size_type __how_much = _M_length() - __pos - __n; + + if (_M_is_shared()) { // Must reallocate. _Rep* __r = _Rep::_S_create(__new_size, _M_capacity(), @@ -625,19 +655,20 @@ namespace __gnu_cxx if (__pos) _S_copy(__r->_M_refdata(), _M_data(), __pos); if (__how_much) - _S_copy(__r->_M_refdata() + __pos + __len2, - _M_data() + __pos + __len1, __how_much); + _S_copy(__r->_M_refdata() + __pos, + _M_data() + __pos + __n, __how_much); _M_dispose(); _M_data(__r->_M_refdata()); } - else if (__how_much && __len1 != __len2) + else if (__how_much && __n) { // Work in-place. - _S_move(_M_data() + __pos + __len2, - _M_data() + __pos + __len1, __how_much); + _S_move(_M_data() + __pos, + _M_data() + __pos + __n, __how_much); } - _M_rep()->_M_set_length(__new_size); + + _M_rep()->_M_set_length(__new_size); } } // namespace __gnu_cxx |