You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by vi...@apache.org on 2008/06/20 01:58:34 UTC
svn commit: r669747 - /stdcxx/branches/4.2.x/include/string.cc
Author: vitek
Date: Thu Jun 19 16:58:34 2008
New Revision: 669747
URL: http://svn.apache.org/viewvc?rev=669747&view=rev
Log:
2008-06-19 Travis Vitek <vi...@roguewave.com>
STDCXX-170
* include/string.cc (replace): Make copy of the source sequence
to avoid problems when iterators refer to self. Add a special
case to avoid unnecessary copy when we know that the iterators
do not refer to self.
Modified:
stdcxx/branches/4.2.x/include/string.cc
Modified: stdcxx/branches/4.2.x/include/string.cc
URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/include/string.cc?rev=669747&r1=669746&r2=669747&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/include/string.cc (original)
+++ stdcxx/branches/4.2.x/include/string.cc Thu Jun 19 16:58:34 2008
@@ -34,6 +34,7 @@
# pragma warning (disable: 4345)
#endif // _RWSTD_MSVC
+#include <rw/_typetraits.h>
_RWSTD_NAMESPACE (std) {
@@ -477,6 +478,7 @@
typedef _TYPENAME traits_type::char_type value_type;
typedef _Alloc allocator_type;
typedef _TYPENAME allocator_type::size_type size_type;
+ typedef _TYPENAME allocator_type::const_pointer const_pointer;
typedef _STD::basic_string<_CharT, _Traits, _Alloc> _C_string_type;
@@ -513,10 +515,30 @@
return __s.replace (__pos, __n, size_type (), value_type ());
}
+ if (_RW::__rw_is_pointer<_InputIter>::_C_val) {
+ const const_pointer __beg1 = __s.data ();
+ const const_pointer __end1 = __s.data () + __s.size ();
+
+ const const_pointer __beg2 =
+ _RWSTD_REINTERPRET_CAST (const_pointer, &*__first2);
+ const const_pointer __end2 =
+ _RWSTD_REINTERPRET_CAST (const_pointer, &*__last2);
+
+ // ranges don't overlap, do simple replace
+ if (__end1 < __beg2 || __end2 < __beg1)
+ return __s.__replace_aux (__first1, __last1, __first2, __last2);
+
+ // otherwise fall through and make a copy first
+ }
+
// use a (probably) faster algorithm if possible
if (_STD::__is_bidirectional_iterator (_RWSTD_ITERATOR_CATEGORY(_InputIter,
- __last2)))
- return __s.__replace_aux (__first1, __last1, __first2, __last2);
+ __last2))) {
+ _C_string_type __s3;
+ __s3.__replace_aux (__s3.begin (), __s3.begin (), __first2, __last2);
+
+ return __s.__replace_aux (__first1, __last1, __s3.begin (), __s3.end ());
+ }
_C_string_type __s3;
_TYPENAME _C_string_type::iterator __first3 = __s3.begin ();
@@ -596,6 +618,8 @@
# endif // _RWSTD_NO_STRING_OUTLINED_MEMBER_TEMPLATES
+ // assumes that the two ranges do not overlap
+
_RWSTD_ASSERT_RANGE (__first1, __s._C_make_iter (__s._C_data
+ __s.size ()));
_RWSTD_ASSERT_RANGE (__first1, __last1);
RE: svn commit: r669747 - /stdcxx/branches/4.2.x/include/string.cc
Posted by Travis Vitek <Tr...@roguewave.com>.
Eric Lemings wrote:
>
>
>> Author: vitek
>> Date: Thu Jun 19 16:58:34 2008
>> New Revision: 669747
>...
>>
>> +#include <rw/_typetraits.h>
>>
>
>Uhgh. The missing underscore in that header name just really bugs me
>for some reason. Any objections to renaming it as <rw/_type_traits.h>
>and updating all code that includes it? Its an internal header so we
>have that privilage and no end-user code should be affected.
I don't like it either, but I think it will be best to just leave it
as-is. I'm pretty sure that file is going to go away for 4.3 and later,
so we'd just be making (a little) more work for ourselves in the
meantime.
>Brad.
>
RE: svn commit: r669747 - /stdcxx/branches/4.2.x/include/string.cc
Posted by Eric Lemings <Er...@roguewave.com>.
> -----Original Message-----
> From: vitek@apache.org [mailto:vitek@apache.org]
> Sent: Thursday, June 19, 2008 5:59 PM
> To: commits@stdcxx.apache.org
> Subject: svn commit: r669747 -
> /stdcxx/branches/4.2.x/include/string.cc
>
> Author: vitek
> Date: Thu Jun 19 16:58:34 2008
> New Revision: 669747
...
>
> +#include <rw/_typetraits.h>
>
Uhgh. The missing underscore in that header name just really bugs me
for some reason. Any objections to renaming it as <rw/_type_traits.h>
and updating all code that includes it? Its an internal header so we
have that privilage and no end-user code should be affected.
Brad.