This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Simplify _S_construct(..., input_iterator_tag)
- From: Paolo Carlini <pcarlini at suse dot de>
- To: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 30 Jan 2004 11:02:42 +0100
- Subject: [v3] Simplify _S_construct(..., input_iterator_tag)
Hi,
regtested x86-linux (+ some additional tests), committed to mainline.
Paolo.
////////////////
2004-01-30 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.tcc (_S_construct(_InIterator,
_InIterator, const _Alloc&, input_iterator_tag)): Simplify
the double loop, streamline.
* include/bits/basic_string.tcc: Very minor tweaks.
diff -prN libstdc++-v3-orig/include/bits/basic_string.tcc libstdc++-v3/include/bits/basic_string.tcc
*** libstdc++-v3-orig/include/bits/basic_string.tcc Wed Jan 28 11:37:32 2004
--- libstdc++-v3/include/bits/basic_string.tcc Fri Jan 30 10:06:13 2004
*************** namespace std
*** 92,136 ****
return _S_empty_rep()._M_refdata();
// Avoid reallocation for common case.
_CharT __buf[100];
! size_type __i = 0;
! while (__beg != __end && __i < sizeof(__buf) / sizeof(_CharT))
{
! __buf[__i++] = *__beg;
! ++__beg;
}
! _Rep* __r = _Rep::_S_create(__i, size_type(0), __a);
! traits_type::copy(__r->_M_refdata(), __buf, __i);
! __r->_M_length = __i;
try
{
! // NB: this loop looks precisely this way because
! // it avoids comparing __beg != __end any more
! // than strictly necessary; != might be expensive!
! for (;;)
{
! _CharT* __p = __r->_M_refdata() + __r->_M_length;
! _CharT* __last = __r->_M_refdata() + __r->_M_capacity;
! for (;;)
{
! if (__beg == __end)
! {
! __r->_M_length = __p - __r->_M_refdata();
! *__p = _Rep::_S_terminal; // grrr.
! return __r->_M_refdata();
! }
! if (__p == __last)
! break;
! *__p++ = *__beg;
! ++__beg;
}
! // Allocate more space.
! const size_type __len = __r->_M_capacity;
! _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
! traits_type::copy(__another->_M_refdata(),
! __r->_M_refdata(), __len);
! __r->_M_destroy(__a);
! __r = __another;
! __r->_M_length = __len;
}
}
catch(...)
--- 92,120 ----
return _S_empty_rep()._M_refdata();
// Avoid reallocation for common case.
_CharT __buf[100];
! size_type __len = 0;
! while (__beg != __end && __len < sizeof(__buf) / sizeof(_CharT))
{
! __buf[__len++] = *__beg;
! ++__beg;
}
! _Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
! traits_type::copy(__r->_M_refdata(), __buf, __len);
try
{
! while (__beg != __end)
{
! if (__len == __r->_M_capacity)
{
! // Allocate more space.
! _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
! traits_type::copy(__another->_M_refdata(),
! __r->_M_refdata(), __len);
! __r->_M_destroy(__a);
! __r = __another;
}
! __r->_M_refdata()[__len++] = *__beg;
! ++__beg;
}
}
catch(...)
*************** namespace std
*** 138,144 ****
__r->_M_destroy(__a);
__throw_exception_again;
}
! return 0;
}
template<typename _CharT, typename _Traits, typename _Alloc>
--- 122,130 ----
__r->_M_destroy(__a);
__throw_exception_again;
}
! __r->_M_length = __len;
! __r->_M_refdata()[__len] = _Rep::_S_terminal; // grrr.
! return __r->_M_refdata();
}
template<typename _CharT, typename _Traits, typename _Alloc>
*************** namespace std
*** 167,173 ****
__throw_exception_again;
}
__r->_M_length = __dnew;
-
__r->_M_refdata()[__dnew] = _Rep::_S_terminal; // grrr.
return __r->_M_refdata();
}
--- 153,158 ----
*************** namespace std
*** 209,217 ****
: _M_dataplus(_S_construct(__str._M_data()
+ __str._M_check(__pos,
"basic_string::basic_string"),
! __str._M_data() + __pos
! + __str._M_limit(__pos, __n),
! _Alloc()), _Alloc())
{ }
template<typename _CharT, typename _Traits, typename _Alloc>
--- 194,201 ----
: _M_dataplus(_S_construct(__str._M_data()
+ __str._M_check(__pos,
"basic_string::basic_string"),
! __str._M_data() + __str._M_limit(__pos, __n)
! + __pos, _Alloc()), _Alloc())
{ }
template<typename _CharT, typename _Traits, typename _Alloc>
*************** namespace std
*** 221,228 ****
: _M_dataplus(_S_construct(__str._M_data()
+ __str._M_check(__pos,
"basic_string::basic_string"),
! __str._M_data() + __pos
! + __str._M_limit(__pos, __n), __a), __a)
{ }
// TBD: DPG annotate
--- 205,212 ----
: _M_dataplus(_S_construct(__str._M_data()
+ __str._M_check(__pos,
"basic_string::basic_string"),
! __str._M_data() + __str._M_limit(__pos, __n)
! + __pos, __a), __a)
{ }
// TBD: DPG annotate
*************** namespace std
*** 262,268 ****
if (_M_rep() != __str._M_rep())
{
// XXX MT
! allocator_type __a = this->get_allocator();
_CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator());
_M_rep()->_M_dispose(__a);
_M_data(__tmp);
--- 246,252 ----
if (_M_rep() != __str._M_rep())
{
// XXX MT
! const allocator_type __a = this->get_allocator();
_CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator());
_M_rep()->_M_dispose(__a);
_M_data(__tmp);