basic_string.tcc (_S_construct(_InIterator, _InIterator, const _Alloc&, input_iterator_tag)): Simplify the double loop, streamline.
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. From-SVN: r76937
This commit is contained in:
parent
57116d8d9f
commit
690495b0fc
|
@ -1,3 +1,11 @@
|
||||||
|
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.
|
||||||
|
|
||||||
2004-01-30 Loren J. Rittle <ljrittle@acm.org>
|
2004-01-30 Loren J. Rittle <ljrittle@acm.org>
|
||||||
|
|
||||||
* scripts/check_performance: Only compile with $THREAD_FLAG
|
* scripts/check_performance: Only compile with $THREAD_FLAG
|
||||||
|
|
|
@ -92,45 +92,29 @@ namespace std
|
||||||
return _S_empty_rep()._M_refdata();
|
return _S_empty_rep()._M_refdata();
|
||||||
// Avoid reallocation for common case.
|
// Avoid reallocation for common case.
|
||||||
_CharT __buf[100];
|
_CharT __buf[100];
|
||||||
size_type __i = 0;
|
size_type __len = 0;
|
||||||
while (__beg != __end && __i < sizeof(__buf) / sizeof(_CharT))
|
while (__beg != __end && __len < sizeof(__buf) / sizeof(_CharT))
|
||||||
{
|
{
|
||||||
__buf[__i++] = *__beg;
|
__buf[__len++] = *__beg;
|
||||||
++__beg;
|
++__beg;
|
||||||
}
|
}
|
||||||
_Rep* __r = _Rep::_S_create(__i, size_type(0), __a);
|
_Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
|
||||||
traits_type::copy(__r->_M_refdata(), __buf, __i);
|
traits_type::copy(__r->_M_refdata(), __buf, __len);
|
||||||
__r->_M_length = __i;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// NB: this loop looks precisely this way because
|
while (__beg != __end)
|
||||||
// it avoids comparing __beg != __end any more
|
|
||||||
// than strictly necessary; != might be expensive!
|
|
||||||
for (;;)
|
|
||||||
{
|
{
|
||||||
_CharT* __p = __r->_M_refdata() + __r->_M_length;
|
if (__len == __r->_M_capacity)
|
||||||
_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.
|
// Allocate more space.
|
||||||
const size_type __len = __r->_M_capacity;
|
|
||||||
_Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
|
_Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
|
||||||
traits_type::copy(__another->_M_refdata(),
|
traits_type::copy(__another->_M_refdata(),
|
||||||
__r->_M_refdata(), __len);
|
__r->_M_refdata(), __len);
|
||||||
__r->_M_destroy(__a);
|
__r->_M_destroy(__a);
|
||||||
__r = __another;
|
__r = __another;
|
||||||
__r->_M_length = __len;
|
}
|
||||||
|
__r->_M_refdata()[__len++] = *__beg;
|
||||||
|
++__beg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
|
@ -138,7 +122,9 @@ namespace std
|
||||||
__r->_M_destroy(__a);
|
__r->_M_destroy(__a);
|
||||||
__throw_exception_again;
|
__throw_exception_again;
|
||||||
}
|
}
|
||||||
return 0;
|
__r->_M_length = __len;
|
||||||
|
__r->_M_refdata()[__len] = _Rep::_S_terminal; // grrr.
|
||||||
|
return __r->_M_refdata();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||||
|
@ -167,7 +153,6 @@ namespace std
|
||||||
__throw_exception_again;
|
__throw_exception_again;
|
||||||
}
|
}
|
||||||
__r->_M_length = __dnew;
|
__r->_M_length = __dnew;
|
||||||
|
|
||||||
__r->_M_refdata()[__dnew] = _Rep::_S_terminal; // grrr.
|
__r->_M_refdata()[__dnew] = _Rep::_S_terminal; // grrr.
|
||||||
return __r->_M_refdata();
|
return __r->_M_refdata();
|
||||||
}
|
}
|
||||||
|
@ -209,9 +194,8 @@ namespace std
|
||||||
: _M_dataplus(_S_construct(__str._M_data()
|
: _M_dataplus(_S_construct(__str._M_data()
|
||||||
+ __str._M_check(__pos,
|
+ __str._M_check(__pos,
|
||||||
"basic_string::basic_string"),
|
"basic_string::basic_string"),
|
||||||
__str._M_data() + __pos
|
__str._M_data() + __str._M_limit(__pos, __n)
|
||||||
+ __str._M_limit(__pos, __n),
|
+ __pos, _Alloc()), _Alloc())
|
||||||
_Alloc()), _Alloc())
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||||
|
@ -221,8 +205,8 @@ namespace std
|
||||||
: _M_dataplus(_S_construct(__str._M_data()
|
: _M_dataplus(_S_construct(__str._M_data()
|
||||||
+ __str._M_check(__pos,
|
+ __str._M_check(__pos,
|
||||||
"basic_string::basic_string"),
|
"basic_string::basic_string"),
|
||||||
__str._M_data() + __pos
|
__str._M_data() + __str._M_limit(__pos, __n)
|
||||||
+ __str._M_limit(__pos, __n), __a), __a)
|
+ __pos, __a), __a)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// TBD: DPG annotate
|
// TBD: DPG annotate
|
||||||
|
@ -262,7 +246,7 @@ namespace std
|
||||||
if (_M_rep() != __str._M_rep())
|
if (_M_rep() != __str._M_rep())
|
||||||
{
|
{
|
||||||
// XXX MT
|
// XXX MT
|
||||||
allocator_type __a = this->get_allocator();
|
const allocator_type __a = this->get_allocator();
|
||||||
_CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator());
|
_CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator());
|
||||||
_M_rep()->_M_dispose(__a);
|
_M_rep()->_M_dispose(__a);
|
||||||
_M_data(__tmp);
|
_M_data(__tmp);
|
||||||
|
|
Loading…
Reference in New Issue