From a3ac714726d1bc20c2e0385f01ca227d74af95c9 Mon Sep 17 00:00:00 2001 From: paolo Date: Wed, 19 Oct 2005 14:25:31 +0000 Subject: [PATCH] 2005-10-19 Paolo Carlini * include/ext/rc_string_base.h (_S_terminal): Remove. (_M_set_length): Adjust. (_S_max_size): Change to anonymous enum. (_M_max_size()): Add, returns the latter. * include/ext/sso_string_base.h: Likewise. * include/ext/vstring.h (max_size): Adjust. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@105616 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 9 ++++++ libstdc++-v3/include/ext/rc_string_base.h | 51 +++++++++++++----------------- libstdc++-v3/include/ext/sso_string_base.h | 26 ++++++--------- libstdc++-v3/include/ext/vstring.h | 4 +-- 4 files changed, 43 insertions(+), 47 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 48c588f..8927bdd 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2005-10-19 Paolo Carlini + + * include/ext/rc_string_base.h (_S_terminal): Remove. + (_M_set_length): Adjust. + (_S_max_size): Change to anonymous enum. + (_M_max_size()): Add, returns the latter. + * include/ext/sso_string_base.h: Likewise. + * include/ext/vstring.h (max_size): Adjust. + 2005-10-17 Jonathan Wakely PR libstdc++/24244 diff --git a/libstdc++-v3/include/ext/rc_string_base.h b/libstdc++-v3/include/ext/rc_string_base.h index 0b35e38..e462680 100644 --- a/libstdc++-v3/include/ext/rc_string_base.h +++ b/libstdc++-v3/include/ext/rc_string_base.h @@ -96,22 +96,7 @@ namespace __gnu_cxx _CharT_alloc_type _CharT_alloc_type; typedef typename _CharT_alloc_type::size_type size_type; - // The maximum number of individual char_type elements of an - // individual string is determined by _S_max_size. This is the - // value that will be returned by max_size(). (Whereas npos - // is the maximum number of bytes the allocator can allocate.) - // If one was to divvy up the theoretical largest size string, - // with a terminating character and m _CharT elements, it'd - // look like this: - // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT) - // Solving for m: - // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1 - // In addition, this implementation quarters this amount. - static const size_type _S_max_size; - private: - static const _CharT _S_terminal; - // _Rep: string representation // Invariants: // 1. String really contains _M_length + 1 characters: due to 21.3.4 @@ -151,7 +136,7 @@ namespace __gnu_cxx _M_length = __n; // grrr. (per 21.3.4) // You cannot leave those LWG people alone for a second. - traits_type::assign(_M_refdata()[__n], _S_terminal); + traits_type::assign(_M_refdata()[__n], _CharT()); } // Create & Destroy @@ -170,6 +155,20 @@ namespace __gnu_cxx _CharT _M_terminal; }; + // The maximum number of individual char_type elements of an + // individual string is determined by _S_max_size. This is the + // value that will be returned by max_size(). (Whereas npos + // is the maximum number of bytes the allocator can allocate.) + // If one was to divvy up the theoretical largest size string, + // with a terminating character and m _CharT elements, it'd + // look like this: + // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT) + // Solving for m: + // m = ((npos - sizeof(_Rep)) / sizeof(_CharT)) - 1 + // In addition, this implementation quarters this amount. + enum { _S_max_size = (((static_cast(-1) - sizeof(_Rep)) + / sizeof(_CharT)) - 1) / 4 }; + // Use empty-base optimization: http://www.cantrip.org/emptyopt.html struct _Alloc_hider : _Alloc { @@ -257,6 +256,10 @@ namespace __gnu_cxx _S_construct(size_type __req, _CharT __c, const _Alloc& __a); public: + size_type + _M_max_size() const + { return size_type(_S_max_size); } + _CharT* _M_data() const { return _M_dataplus._M_p; } @@ -335,16 +338,6 @@ namespace __gnu_cxx }; template - const typename __rc_string_base<_CharT, _Traits, _Alloc>::size_type - __rc_string_base<_CharT, _Traits, _Alloc>:: - _S_max_size = (((static_cast(-1) - sizeof(_Rep)) - / sizeof(_CharT)) - 1) / 4; - - template - const _CharT - __rc_string_base<_CharT, _Traits, _Alloc>::_S_terminal = _CharT(); - - template typename __rc_string_base<_CharT, _Traits, _Alloc>::_Rep* __rc_string_base<_CharT, _Traits, _Alloc>::_Rep:: _S_create(size_type __capacity, size_type __old_capacity, @@ -352,7 +345,7 @@ namespace __gnu_cxx { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 83. String::npos vs. string::max_size() - if (__capacity > _S_max_size) + if (__capacity > size_type(_S_max_size)) std::__throw_length_error(__N("__rc_string_base::_Rep::_S_create")); // The standard places no restriction on allocating more memory @@ -404,8 +397,8 @@ namespace __gnu_cxx const size_type __extra = __pagesize - __adj_size % __pagesize; __capacity += __extra / sizeof(_CharT); // Never allocate a string bigger than _S_max_size. - if (__capacity > _S_max_size) - __capacity = _S_max_size; + if (__capacity > size_type(_S_max_size)) + __capacity = size_type(_S_max_size); __size = ((__capacity + 1) * sizeof(_CharT) + sizeof(_Rep) + sizeof(size_type) - 1); } diff --git a/libstdc++-v3/include/ext/sso_string_base.h b/libstdc++-v3/include/ext/sso_string_base.h index 24bbae2..e578d24 100644 --- a/libstdc++-v3/include/ext/sso_string_base.h +++ b/libstdc++-v3/include/ext/sso_string_base.h @@ -51,6 +51,7 @@ namespace __gnu_cxx _CharT_alloc_type _CharT_alloc_type; typedef typename _CharT_alloc_type::size_type size_type; + private: // The maximum number of individual char_type elements of an // individual string is determined by _S_max_size. This is the // value that will be returned by max_size(). (Whereas npos @@ -60,13 +61,11 @@ namespace __gnu_cxx // look like this: // npos = m * sizeof(_CharT) + sizeof(_CharT) // Solving for m: - // m = npos / sizeof(CharT) - 1 + // m = npos / sizeof(_CharT) - 1 // In addition, this implementation quarters this amount. - static const size_type _S_max_size; + enum { _S_max_size = (((static_cast(-1) + / sizeof(_CharT)) - 1) / 4) }; - private: - static const _CharT _S_terminal; - // Use empty-base optimization: http://www.cantrip.org/emptyopt.html struct _Alloc_hider : _Alloc { @@ -159,6 +158,10 @@ namespace __gnu_cxx _M_construct(size_type __req, _CharT __c); public: + size_type + _M_max_size() const + { return size_type(_S_max_size); } + _CharT* _M_data() const { return _M_dataplus._M_p; } @@ -194,7 +197,7 @@ namespace __gnu_cxx _M_length(__n); // grrr. (per 21.3.4) // You cannot leave those LWG people alone for a second. - traits_type::assign(_M_data()[__n], _S_terminal); + traits_type::assign(_M_data()[__n], _CharT()); } void @@ -297,22 +300,13 @@ namespace __gnu_cxx } template - const typename __sso_string_base<_CharT, _Traits, _Alloc>::size_type - __sso_string_base<_CharT, _Traits, _Alloc>:: - _S_max_size = ((static_cast(-1) / sizeof(_CharT)) - 1) / 4; - - template - const _CharT - __sso_string_base<_CharT, _Traits, _Alloc>::_S_terminal = _CharT(); - - template _CharT* __sso_string_base<_CharT, _Traits, _Alloc>:: _M_create(size_type& __capacity, size_type __old_capacity) { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 83. String::npos vs. string::max_size() - if (__capacity > _S_max_size) + if (__capacity > size_type(_S_max_size)) std::__throw_length_error(__N("__sso_string_base::_M_create")); // The below implements an exponential growth policy, necessary to diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index abea0a9..a774194 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -73,7 +73,7 @@ namespace __gnu_cxx typedef std::reverse_iterator const_reverse_iterator; typedef std::reverse_iterator reverse_iterator; - // Data Members (public): + // Data Member (public): // NB: This is an unsigned type, and thus represents the maximum // size that the allocator can hold. /// Value returned by various member functions when they fail. @@ -346,7 +346,7 @@ namespace __gnu_cxx /// Returns the size() of the largest possible %string. size_type max_size() const - { return __vstring_base::_S_max_size; } + { return this->_M_max_size(); } /** * @brief Resizes the %string to the specified number of characters. -- 2.7.4