basic_string.tcc (replace(size_type, size_type, const _CharT*, size_type)): Implement optimized in-place algorithm for non-overlapping ranges.
2004-01-26 Paolo Carlini <pcarlini@suse.de> * include/bits/basic_string.tcc (replace(size_type, size_type, const _CharT*, size_type)): Implement optimized in-place algorithm for non-overlapping ranges. * testsuite/21_strings/basic_string/replace/char/6.cc: New. * testsuite/21_strings/basic_string/replace/wchar_t/6.cc: New. * include/bits/basic_string.tcc (insert(size_type, const _CharT*, size_type)): Tweak slightly. From-SVN: r76625
This commit is contained in:
parent
6865f4cd9f
commit
2cb612d1b0
@ -1,3 +1,14 @@
|
|||||||
|
2004-01-26 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
* include/bits/basic_string.tcc (replace(size_type,
|
||||||
|
size_type, const _CharT*, size_type)): Implement optimized
|
||||||
|
in-place algorithm for non-overlapping ranges.
|
||||||
|
* testsuite/21_strings/basic_string/replace/char/6.cc: New.
|
||||||
|
* testsuite/21_strings/basic_string/replace/wchar_t/6.cc: New.
|
||||||
|
|
||||||
|
* include/bits/basic_string.tcc (insert(size_type,
|
||||||
|
const _CharT*, size_type)): Tweak slightly.
|
||||||
|
|
||||||
2004-01-26 Andreas Schwab <schwab@suse.de>
|
2004-01-26 Andreas Schwab <schwab@suse.de>
|
||||||
|
|
||||||
* config/locale/gnu/monetary_members.cc: Restore locale before
|
* config/locale/gnu/monetary_members.cc: Restore locale before
|
||||||
|
@ -319,8 +319,9 @@ namespace std
|
|||||||
traits_type::copy(__p, __s + __n, __n);
|
traits_type::copy(__p, __s + __n, __n);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
traits_type::copy(__p, __s, __p - __s);
|
const size_type __nleft = __p - __s;
|
||||||
traits_type::copy(__p + (__p-__s), __p + __n, __n - (__p-__s));
|
traits_type::copy(__p, __s, __nleft);
|
||||||
|
traits_type::copy(__p + __nleft, __p + __n, __n - __nleft);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -337,12 +338,27 @@ namespace std
|
|||||||
__n1 = _M_limit(__pos, __n1);
|
__n1 = _M_limit(__pos, __n1);
|
||||||
if (this->max_size() - (this->size() - __n1) < __n2)
|
if (this->max_size() - (this->size() - __n1) < __n2)
|
||||||
__throw_length_error("basic_string::replace");
|
__throw_length_error("basic_string::replace");
|
||||||
|
bool __left;
|
||||||
if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data())
|
if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data())
|
||||||
|| less<const _CharT*>()(_M_data() + this->size(), __s))
|
|| less<const _CharT*>()(_M_data() + this->size(), __s))
|
||||||
return _M_replace_safe(__pos, __n1, __s, __n2);
|
return _M_replace_safe(__pos, __n1, __s, __n2);
|
||||||
|
else if ((__left = __s + __n2 <= _M_data() + __pos)
|
||||||
|
|| _M_data() + __pos + __n1 <= __s)
|
||||||
|
{
|
||||||
|
// Work in-place: non-overlapping case.
|
||||||
|
const size_type __off = __s - _M_data();
|
||||||
|
_M_mutate(__pos, __n1, __n2);
|
||||||
|
if (__left)
|
||||||
|
traits_type::copy(_M_data() + __pos,
|
||||||
|
_M_data() + __off, __n2);
|
||||||
|
else
|
||||||
|
traits_type::copy(_M_data() + __pos,
|
||||||
|
_M_data() + __off + __n2 - __n1, __n2);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Todo: optimized in-place replace.
|
// Todo: overlapping case.
|
||||||
const basic_string __tmp(__s, __n2);
|
const basic_string __tmp(__s, __n2);
|
||||||
return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
|
return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
// 2004-01-26 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||||
|
//
|
||||||
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
// terms of the GNU General Public License as published by the
|
||||||
|
// Free Software Foundation; either version 2, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this library; see the file COPYING. If not, write to the Free
|
||||||
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
// USA.
|
||||||
|
|
||||||
|
// 21.3.5.6 basic_string::replace
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
|
||||||
|
std::string str01("Valle Del Salto");
|
||||||
|
str01.replace(0, 5, str01.data() + 10, 5);
|
||||||
|
VERIFY( str01 == "Salto Del Salto" );
|
||||||
|
|
||||||
|
std::string str02("Colle di Val d'Elsa");
|
||||||
|
str02.replace(0, 9, str02.data() + 10, 0);
|
||||||
|
VERIFY( str02 == "Val d'Elsa" );
|
||||||
|
|
||||||
|
std::string str03("Novi Ligure");
|
||||||
|
str03.replace(11, 0, str03.data() + 4, 7);
|
||||||
|
VERIFY( str03 == "Novi Ligure Ligure");
|
||||||
|
|
||||||
|
std::string str04("Trebisacce");
|
||||||
|
str04.replace(3, 4, str04.data(), 0);
|
||||||
|
VERIFY( str04 == "Trecce" );
|
||||||
|
|
||||||
|
std::string str05("Altopiano della Sila");
|
||||||
|
str05.replace(1, 18, str05.data() + 19, 1);
|
||||||
|
VERIFY( str05 == "Aaa" );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
// 2004-01-26 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||||
|
//
|
||||||
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
// terms of the GNU General Public License as published by the
|
||||||
|
// Free Software Foundation; either version 2, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this library; see the file COPYING. If not, write to the Free
|
||||||
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
// USA.
|
||||||
|
|
||||||
|
// 21.3.5.6 basic_string::replace
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
|
||||||
|
std::wstring str01(L"Valle Del Salto");
|
||||||
|
str01.replace(0, 5, str01.data() + 10, 5);
|
||||||
|
VERIFY( str01 == L"Salto Del Salto" );
|
||||||
|
|
||||||
|
std::wstring str02(L"Colle di Val d'Elsa");
|
||||||
|
str02.replace(0, 9, str02.data() + 10, 0);
|
||||||
|
VERIFY( str02 == L"Val d'Elsa" );
|
||||||
|
|
||||||
|
std::wstring str03(L"Novi Ligure");
|
||||||
|
str03.replace(11, 0, str03.data() + 4, 7);
|
||||||
|
VERIFY( str03 == L"Novi Ligure Ligure");
|
||||||
|
|
||||||
|
std::wstring str04(L"Trebisacce");
|
||||||
|
str04.replace(3, 4, str04.data(), 0);
|
||||||
|
VERIFY( str04 == L"Trecce" );
|
||||||
|
|
||||||
|
std::wstring str05(L"Altopiano della Sila");
|
||||||
|
str05.replace(1, 18, str05.data() + 19, 1);
|
||||||
|
VERIFY( str05 == L"Aaa" );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user