Drastic fix for Vladimir's link problem

Paolo Carlini pcarlini@unitus.it
Wed Dec 12 05:47:00 GMT 2001


Hi,

Vladimir reported link problems
(http://gcc.gnu.org/ml/libstdc++/2001-12/msg00201.html) most probably caused by
my recent commits affecting the string class.

Honestly, right now I do not fully understand them (Benjamin, could you possibly
help me a little bit here?), therefore, if nothing simpler may be prepared in
the next hours I propose the following fix, that restores the general asset
preceding my commits. Notice, that it is *not* a revert (all the speedups are
still there ;-) but is reintroduced some redundancy:
_M_replace(forward_iterator_tag) and _M_replace(input_iterator_tag) are
identical.

I have checked that on i686-pc-linux-gnu there are no regressions.

Vladimir, could you possibly test the patch ASAP ??

Cheers,
Paolo.


////////////

diff -urN libstdc++-v3-vanilla/include/bits/basic_string.h
libstdc++-v3/include/bits/basic_string.h
--- libstdc++-v3-vanilla/include/bits/basic_string.h Mon Dec 10 15:18:27 2001
+++ libstdc++-v3/include/bits/basic_string.h Wed Dec 12 13:44:48 2001
@@ -641,6 +641,11 @@

       template<class _ForwardIterator>
         basic_string&
+        _M_replace(iterator __i1, iterator __i2, _ForwardIterator __k1,
+     _ForwardIterator __k2, forward_iterator_tag);
+
+      template<class _ForwardIterator>
+        basic_string&
         _M_replace_safe(iterator __i1, iterator __i2, _ForwardIterator __k1,
      _ForwardIterator __k2);

diff -urN libstdc++-v3-vanilla/include/bits/basic_string.tcc
libstdc++-v3/include/bits/basic_string.tcc
--- libstdc++-v3-vanilla/include/bits/basic_string.tcc Mon Dec 10 14:45:41 2001
+++ libstdc++-v3/include/bits/basic_string.tcc Wed Dec 12 14:05:50 2001
@@ -490,19 +490,30 @@
       // else nothing (in particular, avoid calling _M_mutate() unnecessarily.)

     }

-  // This is the general replace helper, which gets instantiated both
-  // for input-iterators and forward-iterators. It buffers internally and
+  // This are the general replace helpers, which get instantiated for
+  // input-iterators and forward-iterators. They buffer internally and
   // then calls _M_replace_safe. For input-iterators this is almost the
   // best we can do, but for forward-iterators many optimizations could be
   // conceived: f.i., when source and destination ranges do not overlap
-  // buffering is not really needed. In order to easily implement them, it
-  // could become useful to add an _M_replace(forward_iterator_tag)
+  // buffering is not really needed.
   template<typename _CharT, typename _Traits, typename _Alloc>
     template<typename _InputIter>
       basic_string<_CharT, _Traits, _Alloc>&
       basic_string<_CharT, _Traits, _Alloc>::
       _M_replace(iterator __i1, iterator __i2, _InputIter __k1,
    _InputIter __k2, input_iterator_tag)
+      {
+ // Save concerned source string data in a temporary.
+ basic_string __s(__k1, __k2);
+ return _M_replace_safe(__i1, __i2, __s._M_ibegin(), __s._M_iend());
+      }
+
+  template<typename _CharT, typename _Traits, typename _Alloc>
+    template<typename _ForwardIter>
+      basic_string<_CharT, _Traits, _Alloc>&
+      basic_string<_CharT, _Traits, _Alloc>::
+      _M_replace(iterator __i1, iterator __i2, _ForwardIter __k1,
+   _ForwardIter __k2, forward_iterator_tag)
       {
  // Save concerned source string data in a temporary.
  basic_string __s(__k1, __k2);
diff -urN libstdc++-v3-vanilla/src/string-inst.cc
libstdc++-v3/src/string-inst.cc
--- libstdc++-v3-vanilla/src/string-inst.cc Sun Dec  9 12:10:22 2001
+++ libstdc++-v3/src/string-inst.cc Wed Dec 12 13:10:49 2001
@@ -71,21 +71,21 @@
   template
     S&
     S::_M_replace(S::iterator, S::iterator, S::iterator, S::iterator,
-    input_iterator_tag);
+    forward_iterator_tag);

   template
     S&
     S::_M_replace(S::iterator, S::iterator, S::const_iterator,
-    S::const_iterator, input_iterator_tag);
+    S::const_iterator, forward_iterator_tag);

   template
     S&
-    S::_M_replace(S::iterator, S::iterator, C*, C*, input_iterator_tag);
+    S::_M_replace(S::iterator, S::iterator, C*, C*, forward_iterator_tag);

   template
     S&
     S::_M_replace(S::iterator, S::iterator, const C*, const C*,
-    input_iterator_tag);
+    forward_iterator_tag);

   template
     S&




More information about the Libstdc++ mailing list