aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2005-10-19 14:25:31 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2005-10-19 14:25:31 +0000
commit486516b60ba69fa8bd5fd13a9e4f630642d18546 (patch)
tree1574610f046d1f60505b52e0354fe6d251919f8c
parent0bf72672367ae1c7110a042dda32dafa771c2f86 (diff)
downloadgcc-486516b60ba69fa8bd5fd13a9e4f630642d18546.zip
gcc-486516b60ba69fa8bd5fd13a9e4f630642d18546.tar.gz
gcc-486516b60ba69fa8bd5fd13a9e4f630642d18546.tar.bz2
rc_string_base.h (_S_terminal): Remove.
2005-10-19 Paolo Carlini <pcarlini@suse.de> * 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. From-SVN: r105616
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/ext/rc_string_base.h51
-rw-r--r--libstdc++-v3/include/ext/sso_string_base.h26
-rw-r--r--libstdc++-v3/include/ext/vstring.h4
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 <pcarlini@suse.de>
+
+ * 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 <redi@gcc.gnu.org>
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<size_type>(-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<typename _CharT, typename _Traits, typename _Alloc>
- const typename __rc_string_base<_CharT, _Traits, _Alloc>::size_type
- __rc_string_base<_CharT, _Traits, _Alloc>::
- _S_max_size = (((static_cast<size_type>(-1) - sizeof(_Rep))
- / sizeof(_CharT)) - 1) / 4;
-
- template<typename _CharT, typename _Traits, typename _Alloc>
- const _CharT
- __rc_string_base<_CharT, _Traits, _Alloc>::_S_terminal = _CharT();
-
- template<typename _CharT, typename _Traits, typename _Alloc>
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<size_type>(-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<typename _CharT, typename _Traits, typename _Alloc>
- const typename __sso_string_base<_CharT, _Traits, _Alloc>::size_type
- __sso_string_base<_CharT, _Traits, _Alloc>::
- _S_max_size = ((static_cast<size_type>(-1) / sizeof(_CharT)) - 1) / 4;
-
- template<typename _CharT, typename _Traits, typename _Alloc>
- const _CharT
- __sso_string_base<_CharT, _Traits, _Alloc>::_S_terminal = _CharT();
-
- template<typename _CharT, typename _Traits, typename _Alloc>
_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_iterator> const_reverse_iterator;
typedef std::reverse_iterator<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.