This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Basic_string::_M_mutate tweak (+ minor reformats)
- 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: Mon, 18 Oct 2004 10:46:41 +0200
- Subject: [v3] Basic_string::_M_mutate tweak (+ minor reformats)
Hi,
tested x86-linux, committed to mainline.
Paolo.
/////////////////
2004-10-18 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.tcc (_M_mutate): Do not reallocate
unnecessarily when _M_rep() == &_S_empty_rep() and __new_size
== capacity() (== 0): is ok to just leave everything unchanged.
* include/bits/basic_string.h: Minor formatting fixes.
* include/bits/basic_string.tcc: Likewise.
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-09-28 10:58:31.000000000 +0200
+++ libstdc++-v3/include/bits/basic_string.h 2004-10-17 20:07:16.000000000 +0200
@@ -271,10 +271,12 @@
// For the internal use we have functions similar to `begin'/`end'
// but they do not call _M_leak.
iterator
- _M_ibegin() const { return iterator(_M_data()); }
+ _M_ibegin() const
+ { return iterator(_M_data()); }
iterator
- _M_iend() const { return iterator(_M_data() + this->size()); }
+ _M_iend() const
+ { return iterator(_M_data() + this->size()); }
void
_M_leak() // for use in begin() & non-const op[]
@@ -527,16 +529,19 @@
/// Returns the number of characters in the string, not including any
/// null-termination.
size_type
- size() const { return _M_rep()->_M_length; }
+ size() const
+ { return _M_rep()->_M_length; }
/// Returns the number of characters in the string, not including any
/// null-termination.
size_type
- length() const { return _M_rep()->_M_length; }
+ length() const
+ { return _M_rep()->_M_length; }
/// Returns the size() of the largest possible %string.
size_type
- max_size() const { return _Rep::_S_max_size; }
+ max_size() const
+ { return _Rep::_S_max_size; }
/**
* @brief Resizes the %string to the specified number of characters.
@@ -562,14 +567,16 @@
* setting them to 0.
*/
void
- resize(size_type __n) { this->resize(__n, _CharT()); }
+ resize(size_type __n)
+ { this->resize(__n, _CharT()); }
/**
* Returns the total number of characters that the %string can hold
* before needing to allocate more memory.
*/
size_type
- capacity() const { return _M_rep()->_M_capacity; }
+ capacity() const
+ { return _M_rep()->_M_capacity; }
/**
* @brief Attempt to preallocate enough memory for specified number of
@@ -595,13 +602,15 @@
* Erases the string, making it empty.
*/
void
- clear() { _M_mutate(0, this->size(), 0); }
+ clear()
+ { _M_mutate(0, this->size(), 0); }
/**
* Returns true if the %string is empty. Equivalent to *this == "".
*/
bool
- empty() const { return this->size() == 0; }
+ empty() const
+ { return this->size() == 0; }
// Element access:
/**
@@ -684,7 +693,8 @@
* @return Reference to this string.
*/
basic_string&
- operator+=(const basic_string& __str) { return this->append(__str); }
+ operator+=(const basic_string& __str)
+ { return this->append(__str); }
/**
* @brief Append a C string.
@@ -692,7 +702,8 @@
* @return Reference to this string.
*/
basic_string&
- operator+=(const _CharT* __s) { return this->append(__s); }
+ operator+=(const _CharT* __s)
+ { return this->append(__s); }
/**
* @brief Append a character.
@@ -700,7 +711,8 @@
* @return Reference to this string.
*/
basic_string&
- operator+=(_CharT __c) { return this->append(size_type(1), __c); }
+ operator+=(_CharT __c)
+ { return this->append(size_type(1), __c); }
/**
* @brief Append a string to this string.
@@ -1447,7 +1459,8 @@
* happen.
*/
const _CharT*
- c_str() const { return _M_data(); }
+ c_str() const
+ { return _M_data(); }
/**
* @brief Return const pointer to contents.
@@ -1456,13 +1469,15 @@
* happen.
*/
const _CharT*
- data() const { return _M_data(); }
+ data() const
+ { return _M_data(); }
/**
* @brief Return copy of allocator used to construct this string.
*/
allocator_type
- get_allocator() const { return _M_dataplus; }
+ get_allocator() const
+ { return _M_dataplus; }
/**
* @brief Find position of a C substring.
diff -urN libstdc++-v3-orig/include/bits/basic_string.tcc libstdc++-v3/include/bits/basic_string.tcc
--- libstdc++-v3-orig/include/bits/basic_string.tcc 2004-10-13 10:58:39.000000000 +0200
+++ libstdc++-v3/include/bits/basic_string.tcc 2004-10-17 20:04:05.000000000 +0200
@@ -373,7 +373,8 @@
template<typename _CharT, typename _Traits, typename _Alloc>
void
- basic_string<_CharT, _Traits, _Alloc>::_M_leak_hard()
+ basic_string<_CharT, _Traits, _Alloc>::
+ _M_leak_hard()
{
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
if (_M_rep() == &_S_empty_rep())
@@ -393,16 +394,11 @@
const size_type __new_size = __old_size + __len2 - __len1;
const size_type __how_much = __old_size - __pos - __len1;
-#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
- if (_M_rep() == &_S_empty_rep()
- || _M_rep()->_M_is_shared() || __new_size > capacity())
-#else
- if (_M_rep()->_M_is_shared() || __new_size > capacity())
-#endif
+ if (__new_size > this->capacity() || _M_rep()->_M_is_shared())
{
// Must reallocate.
const allocator_type __a = get_allocator();
- _Rep* __r = _Rep::_S_create(__new_size, capacity(), __a);
+ _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a);
if (__pos)
traits_type::copy(__r->_M_refdata(), _M_data(), __pos);
@@ -427,7 +423,8 @@
template<typename _CharT, typename _Traits, typename _Alloc>
void
- basic_string<_CharT, _Traits, _Alloc>::reserve(size_type __res)
+ basic_string<_CharT, _Traits, _Alloc>::
+ reserve(size_type __res)
{
if (__res != this->capacity() || _M_rep()->_M_is_shared())
{
@@ -444,7 +441,9 @@
}
template<typename _CharT, typename _Traits, typename _Alloc>
- void basic_string<_CharT, _Traits, _Alloc>::swap(basic_string& __s)
+ void
+ basic_string<_CharT, _Traits, _Alloc>::
+ swap(basic_string& __s)
{
if (_M_rep()->_M_is_leaked())
_M_rep()->_M_set_sharable();
@@ -561,7 +560,8 @@
template<typename _CharT, typename _Traits, typename _Alloc>
void
- basic_string<_CharT, _Traits, _Alloc>::resize(size_type __n, _CharT __c)
+ basic_string<_CharT, _Traits, _Alloc>::
+ resize(size_type __n, _CharT __c)
{
if (__n > max_size())
__throw_length_error(__N("basic_string::resize"));