This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Small simplification of string::erase
- 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: Tue, 26 Oct 2004 23:20:46 +0200
- Subject: [v3] Small simplification of string::erase
Hi,
tested x86-linux, committed to mainline.
Paolo.
/////////////
2004-10-26 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.h (erase(size_type, size_type),
erase(iterator), erase(iterator, iterator)): Call _M_mutate
instead of _M_replace_safe, equivalent when the fourth argument
is zero and simpler.
diff -urN libstdc++-v3-orig/include/bits/basic_string.h libstdc++-v3/include/bits/basic_string.h
--- libstdc++-v3-orig/include/bits/basic_string.h 2004-10-25 17:16:48.000000000 +0200
+++ libstdc++-v3/include/bits/basic_string.h 2004-10-26 22:03:48.000000000 +0200
@@ -1140,8 +1140,11 @@
*/
basic_string&
erase(size_type __pos = 0, size_type __n = npos)
- { return _M_replace_safe(_M_check(__pos, "basic_string::erase"),
- _M_limit(__pos, __n), NULL, size_type(0)); }
+ {
+ _M_mutate(_M_check(__pos, "basic_string::erase"),
+ _M_limit(__pos, __n), size_type(0));
+ return *this;
+ }
/**
* @brief Remove one character.
@@ -1157,7 +1160,7 @@
_GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
&& __position < _M_iend());
const size_type __pos = __position - _M_ibegin();
- _M_replace_safe(__pos, size_type(1), NULL, size_type(0));
+ _M_mutate(__pos, size_type(1), size_type(0));
_M_rep()->_M_set_leaked();
return _M_ibegin() + __pos;
}
@@ -1177,7 +1180,7 @@
_GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
&& __last <= _M_iend());
const size_type __pos = __first - _M_ibegin();
- _M_replace_safe(__pos, __last - __first, NULL, size_type(0));
+ _M_mutate(__pos, __last - __first, size_type(0));
_M_rep()->_M_set_leaked();
return _M_ibegin() + __pos;
}