diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 926973d2ea8..0642620f3b2 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2003-04-27 Nathan Myers + + Move some basic_string members out of line because + they are too big to reasonably be inline. + * include/bits/basic_string.h + (assign(const basic_string&, size_type, size_type), + assign(const _CharT*, size_type), + insert(size_type, const basic_string&, size_type, size_type), + insert(size_type, const _CharT*, size_type), + replace(size_type, size_type, const _CharT*, size_type)): + Move from here to... + * include/bits/basic_string.tcc: ...here. + 2003-04-26 Paolo Carlini * include/bits/fstream.tcc (pbackfail): Shorten a bit (10 lines) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index fd56bb81ea0..61ddee3d6f8 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -499,37 +499,10 @@ namespace std assign(const basic_string& __str); basic_string& - assign(const basic_string& __str, size_type __pos, size_type __n) - { - const size_type __strsize = __str.size(); - if (__pos > __strsize) - __throw_out_of_range("basic_string::assign"); - const bool __testn = __n < __strsize - __pos; - const size_type __newsize = __testn ? __n : __strsize - __pos; - return this->assign(__str._M_data() + __pos, __newsize); - } + assign(const basic_string& __str, size_type __pos, size_type __n); basic_string& - assign(const _CharT* __s, size_type __n) - { - if (__n > this->max_size()) - __throw_length_error("basic_string::assign"); - if (_M_rep()->_M_is_shared() || less()(__s, _M_data()) - || less()(_M_data() + this->size(), __s)) - return _M_replace_safe(_M_ibegin(), _M_iend(), __s, __s + __n); - else - { - // Work in-place - const size_type __pos = __s - _M_data(); - if (__pos >= __n) - traits_type::copy(_M_data(), __s, __n); - else if (__pos) - traits_type::move(_M_data(), __s, __n); - _M_rep()->_M_length = __n; - _M_data()[__n] = _Rep::_S_terminal; - return *this; - } - } + assign(const _CharT* __s, size_type __n); basic_string& assign(const _CharT* __s) @@ -558,49 +531,10 @@ namespace std basic_string& insert(size_type __pos1, const basic_string& __str, - size_type __pos2, size_type __n) - { - const size_type __strsize = __str.size(); - if (__pos2 > __strsize) - __throw_out_of_range("basic_string::insert"); - const bool __testn = __n < __strsize - __pos2; - const size_type __newsize = __testn ? __n : __strsize - __pos2; - return this->insert(__pos1, __str._M_data() + __pos2, __newsize); - } + size_type __pos2, size_type __n); basic_string& - insert(size_type __pos, const _CharT* __s, size_type __n) - { - const size_type __size = this->size(); - if (__pos > __size) - __throw_out_of_range("basic_string::insert"); - if (__size > this->max_size() - __n) - __throw_length_error("basic_string::insert"); - if (_M_rep()->_M_is_shared() || less()(__s, _M_data()) - || less()(_M_data() + __size, __s)) - return _M_replace_safe(_M_ibegin() + __pos, _M_ibegin() + __pos, - __s, __s + __n); - else - { - // Work in-place. If _M_mutate reallocates the string, __s - // does not point anymore to valid data, therefore we save its - // offset, then we restore it. - const size_type __off = __s - _M_data(); - _M_mutate(__pos, 0, __n); - __s = _M_data() + __off; - _CharT* __p = _M_data() + __pos; - if (__s + __n <= __p) - traits_type::copy(__p, __s, __n); - else if (__s >= __p) - traits_type::copy(__p, __s + __n, __n); - else - { - traits_type::copy(__p, __s, __p - __s); - traits_type::copy(__p + (__p - __s), __p + __n, __n - (__p - __s)); - } - return *this; - } - } + insert(size_type __pos, const _CharT* __s, size_type __n); basic_string& insert(size_type __pos, const _CharT* __s) @@ -657,25 +591,7 @@ namespace std basic_string& replace(size_type __pos, size_type __n1, const _CharT* __s, - size_type __n2) - { - const size_type __size = this->size(); - if (__pos > __size) - __throw_out_of_range("basic_string::replace"); - const bool __testn1 = __n1 < __size - __pos; - const size_type __foldn1 = __testn1 ? __n1 : __size - __pos; - if (__size - __foldn1 > this->max_size() - __n2) - __throw_length_error("basic_string::replace"); - if (_M_rep()->_M_is_shared() || less()(__s, _M_data()) - || less()(_M_data() + __size, __s)) - return _M_replace_safe(_M_ibegin() + __pos, - _M_ibegin() + __pos + __foldn1, __s, __s + __n2); - // Todo: optimized in-place replace. - else return - _M_replace(_M_ibegin() + __pos, _M_ibegin() + __pos + __foldn1, - __s, __s + __n2, - typename iterator_traits::iterator_category()); - } + size_type __n2); basic_string& replace(size_type __pos, size_type __n1, const _CharT* __s) diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index b7034adadeb..657b997c723 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -254,6 +254,117 @@ namespace std } return *this; } + + template + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + assign(const basic_string& __str, size_type __pos, size_type __n) + { + const size_type __strsize = __str.size(); + if (__pos > __strsize) + __throw_out_of_range("basic_string::assign"); + const bool __testn = __n < __strsize - __pos; + const size_type __newsize = __testn ? __n : __strsize - __pos; + return this->assign(__str._M_data() + __pos, __newsize); + } + + template + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + assign(const _CharT* __s, size_type __n) + { + if (__n > this->max_size()) + __throw_length_error("basic_string::assign"); + if (_M_rep()->_M_is_shared() || less()(__s, _M_data()) + || less()(_M_data() + this->size(), __s)) + return _M_replace_safe(_M_ibegin(), _M_iend(), __s, __s + __n); + else + { + // Work in-place + const size_type __pos = __s - _M_data(); + if (__pos >= __n) + traits_type::copy(_M_data(), __s, __n); + else if (__pos) + traits_type::move(_M_data(), __s, __n); + _M_rep()->_M_length = __n; + _M_data()[__n] = _Rep::_S_terminal; // grr. + return *this; + } + } + + template + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + insert(size_type __pos1, const basic_string& __str, + size_type __pos2, size_type __n) + { + const size_type __strsize = __str.size(); + if (__pos2 > __strsize) + __throw_out_of_range("basic_string::insert"); + const bool __testn = __n < __strsize - __pos2; + const size_type __newsize = __testn ? __n : __strsize - __pos2; + return this->insert(__pos1, __str._M_data() + __pos2, __newsize); + } + + template + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + insert(size_type __pos, const _CharT* __s, size_type __n) + { + const size_type __size = this->size(); + if (__pos > __size) + __throw_out_of_range("basic_string::insert"); + if (__size > this->max_size() - __n) + __throw_length_error("basic_string::insert"); + if (_M_rep()->_M_is_shared() || less()(__s, _M_data()) + || less()(_M_data() + __size, __s)) + return _M_replace_safe(_M_ibegin() + __pos, _M_ibegin() + __pos, + __s, __s + __n); + else + { + // Work in-place. If _M_mutate reallocates the string, __s + // does not point anymore to valid data, therefore we save its + // offset, then we restore it. + const size_type __off = __s - _M_data(); + _M_mutate(__pos, 0, __n); + __s = _M_data() + __off; + _CharT* __p = _M_data() + __pos; + if (__s + __n <= __p) + traits_type::copy(__p, __s, __n); + else if (__s >= __p) + traits_type::copy(__p, __s + __n, __n); + else + { + traits_type::copy(__p, __s, __p - __s); + traits_type::copy(__p + (__p-__s), __p + __n, __n - (__p-__s)); + } + return *this; + } + } + + template + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + replace(size_type __pos, size_type __n1, const _CharT* __s, + size_type __n2) + { + const size_type __size = this->size(); + if (__pos > __size) + __throw_out_of_range("basic_string::replace"); + const bool __testn1 = __n1 < __size - __pos; + const size_type __foldn1 = __testn1 ? __n1 : __size - __pos; + if (__size - __foldn1 > this->max_size() - __n2) + __throw_length_error("basic_string::replace"); + if (_M_rep()->_M_is_shared() || less()(__s, _M_data()) + || less()(_M_data() + __size, __s)) + return _M_replace_safe(_M_ibegin() + __pos, + _M_ibegin() + __pos + __foldn1, __s, __s + __n2); + // Todo: optimized in-place replace. + else + return _M_replace(_M_ibegin() + __pos, _M_ibegin() + __pos + __foldn1, + __s, __s + __n2, + typename iterator_traits::iterator_category()); + } template void