Commit 8eae76be by Paolo Carlini Committed by Paolo Carlini

basic_string.h (_Rep::_M_is_safe): Move to basic_string as _M_disjunct, adjust to take only __s.

2004-10-25  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/basic_string.h (_Rep::_M_is_safe): Move to
	basic_string as _M_disjunct, adjust to take only __s.
	* include/bits/basic_string.tcc: Adjust consistently callers.

From-SVN: r89534
parent 4c7c0c70
2004-10-25 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.h (_Rep::_M_is_safe): Move to
basic_string as _M_disjunct, adjust to take only __s.
* include/bits/basic_string.tcc: Adjust consistently callers.
2004-10-25 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.tcc (assign(const _CharT*, size_type)):
Adjust bit missing from the previous commit.
......
......@@ -185,14 +185,6 @@ namespace std
_M_is_shared() const
{ return this->_M_refcount > 0; }
// True if source and destination do not overlap.
bool
_M_is_safe(const _CharT* __data, const _CharT* __s) const
{
return (less<const _CharT*>()(__s, __data)
|| less<const _CharT*>()(__data + this->_M_length, __s));
}
void
_M_set_leaked()
{ this->_M_refcount = -1; }
......@@ -325,6 +317,14 @@ namespace std
return __testoff ? __off : this->size() - __pos;
}
// True if _Rep and source do not overlap.
bool
_M_disjunct(const _CharT* __s) const
{
return (less<const _CharT*>()(__s, _M_data())
|| less<const _CharT*>()(_M_data() + this->size(), __s));
}
// When __n = 1 way faster than the general multichar
// traits_type::copy/move/assign.
static void
......
......@@ -246,7 +246,7 @@ namespace std
{
__glibcxx_requires_string_len(__s, __n);
_M_check_length(this->size(), __n, "basic_string::assign");
if (_M_rep()->_M_is_safe(_M_data(), __s) || _M_rep()->_M_is_shared())
if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
return _M_replace_safe(size_type(0), this->size(), __s, __n);
else
{
......@@ -273,7 +273,7 @@ namespace std
const size_type __len = __n + this->size();
if (__len > this->capacity() || _M_rep()->_M_is_shared())
{
if (_M_rep()->_M_is_safe(_M_data(), __s))
if (_M_disjunct(__s))
this->reserve(__len);
else
{
......@@ -314,7 +314,7 @@ namespace std
__glibcxx_requires_string_len(__s, __n);
_M_check(__pos, "basic_string::insert");
_M_check_length(size_type(0), __n, "basic_string::insert");
if (_M_rep()->_M_is_safe(_M_data(), __s) || _M_rep()->_M_is_shared())
if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
return _M_replace_safe(__pos, size_type(0), __s, __n);
else
{
......@@ -348,7 +348,7 @@ namespace std
__n1 = _M_limit(__pos, __n1);
_M_check_length(__n1, __n2, "basic_string::replace");
bool __left;
if (_M_rep()->_M_is_safe(_M_data(), __s) || _M_rep()->_M_is_shared())
if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
return _M_replace_safe(__pos, __n1, __s, __n2);
else if ((__left = __s + __n2 <= _M_data() + __pos)
|| _M_data() + __pos + __n1 <= __s)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment