This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Simple basic_string changes


Hi,

tested x86-linux, committed to mainline.

Paolo.

////////////
2004-01-18  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/basic_string.h (append(size_type, _CharT)):
	Moved inline, just call _M_replace_aux, no source iterators at
	risk of being clobbered.
	(assign(size_type, _CharT)): Call directly _M_replace_aux.
	(_M_replace(iterator, iterator, _InputIterator, _InputIterator,
	input_iterator_tag)): Remove fifth unused argument.
	(_M_replace_dispatch(iterator, iterator, _InputIterator,
	_InputIterator, __false_type)): Update call.
	* include/bits/basic_string.tcc (replace(size_type, size_type,
	const _CharT*, size_type)): Update call.
	(_M_replace_aux(iterator, iterator, size_type, _CharT)): Tweak
	throw string literal.
	(_M_replace_safe(iterator, iterator, _ForwardIterator,
	_ForwardIterator)): Likewise.
	(_M_replace(iterator, iterator, _InputIterator, _InputIterator,
	input_iterator_tag)): Remove fifth unused argument.
	(append(size_type __n, _CharT __c)): Move inline.
	* src/string-inst.cc (S::_M_replace(S::iterator, S::iterator,
	const C*, const C*, input_iterator_tag)): Remove fifth unused
	argument.
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-01-13 12:12:36.000000000 +0100
+++ libstdc++-v3/include/bits/basic_string.h	2004-01-17 18:53:52.000000000 +0100
@@ -1,6 +1,6 @@
 // Components for manipulating sequences of characters -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -751,7 +751,8 @@
        *  Appends n copies of c to this string.
        */
       basic_string&
-      append(size_type __n, _CharT __c);
+      append(size_type __n, _CharT __c)
+      { return _M_replace_aux(_M_iend(), _M_iend(), __n, __c); }
 
       /**
        *  @brief  Append a range of characters.
@@ -837,7 +838,7 @@
        */
       basic_string&
       assign(size_type __n, _CharT __c)
-      { return this->replace(_M_ibegin(), _M_iend(), __n, __c); }
+      { return _M_replace_aux(_M_ibegin(), _M_iend(), __n, __c); }
 
       /**
        *  @brief  Set value to a range of characters.
@@ -1362,11 +1363,7 @@
 	basic_string&
 	_M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
 			    _InputIterator __k2, __false_type)
-        { 
-	  typedef typename iterator_traits<_InputIterator>::iterator_category
-	    _Category;
-	  return _M_replace(__i1, __i2, __k1, __k2, _Category());
-	}
+        { return _M_replace(__i1, __i2, __k1, __k2); }
 
       basic_string&
       _M_replace_aux(iterator __i1, iterator __i2, size_type __n2, _CharT __c);
@@ -1374,7 +1371,7 @@
       template<class _InputIterator>
         basic_string&
         _M_replace(iterator __i1, iterator __i2, _InputIterator __k1,
-		   _InputIterator __k2, input_iterator_tag);
+		   _InputIterator __k2);
 
       template<class _ForwardIterator>
         basic_string&
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-01-13 12:12:37.000000000 +0100
+++ libstdc++-v3/include/bits/basic_string.tcc	2004-01-17 18:55:18.000000000 +0100
@@ -1,6 +1,6 @@
 // Components for manipulating sequences of characters -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -380,8 +380,7 @@
        // Todo: optimized in-place replace.
        else
 	 return _M_replace(_M_ibegin() + __pos, _M_ibegin() + __pos + __foldn1,
-			   __s, __s + __n2,
-			   typename iterator_traits<const _CharT*>::iterator_category());
+			   __s, __s + __n2);
      }
   
   template<typename _CharT, typename _Traits, typename _Alloc>
@@ -642,23 +641,22 @@
       const size_type __n1 = __i2 - __i1;
       const size_type __off1 = __i1 - _M_ibegin();
       if (max_size() - (this->size() - __n1) <= __n2)
-	__throw_length_error("basic_string::replace");
-      _M_mutate (__off1, __n1, __n2);
+	__throw_length_error("basic_string::_M_replace_aux");
+      _M_mutate(__off1, __n1, __n2);
       // Invalidated __i1, __i2
       if (__n2)
 	traits_type::assign(_M_data() + __off1, __n2, __c);
       return *this;
     }
 
-  // This is the general replace helper, which currently gets instantiated both
-  // for input iterators and reverse iterators. It buffers internally and then
-  // calls _M_replace_safe.
+  // This is the general replace helper. It buffers internally and then calls
+  // _M_replace_safe.
   template<typename _CharT, typename _Traits, typename _Alloc>
     template<typename _InputIterator>
       basic_string<_CharT, _Traits, _Alloc>&
       basic_string<_CharT, _Traits, _Alloc>::
       _M_replace(iterator __i1, iterator __i2, _InputIterator __k1, 
-		 _InputIterator __k2, input_iterator_tag)
+		 _InputIterator __k2)
       {
 	// Save concerned source string data in a temporary.
 	const basic_string __s(__k1, __k2);
@@ -680,7 +678,7 @@
 	const size_type __dmax = this->max_size();
 
 	if (__dmax <= __dnew)
-	  __throw_length_error("basic_string::_M_replace");
+	  __throw_length_error("basic_string::_M_replace_safe");
 	const size_type __off = __i1 - _M_ibegin();
 	_M_mutate(__off, __dold, __dnew);
 
@@ -751,17 +749,6 @@
     }
 
   template<typename _CharT, typename _Traits, typename _Alloc>
-    basic_string<_CharT, _Traits, _Alloc>&
-    basic_string<_CharT, _Traits, _Alloc>::
-    append(size_type __n, _CharT __c)
-    {
-      const size_type __len = __n + this->size();
-      if (__len > this->capacity())
-	this->reserve(__len);
-       return this->replace(_M_iend(), _M_iend(), __n, __c);
-    }
-
-  template<typename _CharT, typename _Traits, typename _Alloc>
     basic_string<_CharT, _Traits, _Alloc>
     operator+(const _CharT* __lhs,
 	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
diff -urN libstdc++-v3-orig/src/string-inst.cc libstdc++-v3/src/string-inst.cc
--- libstdc++-v3-orig/src/string-inst.cc	2003-11-11 21:09:13.000000000 +0100
+++ libstdc++-v3/src/string-inst.cc	2004-01-17 19:02:36.000000000 +0100
@@ -65,8 +65,7 @@
 
   template
     S&
-    S::_M_replace(S::iterator, S::iterator, const C*, const C*, 
-		  input_iterator_tag);  
+    S::_M_replace(S::iterator, S::iterator, const C*, const C*);  
 
   template 
     S& 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]