diff options
author | Paolo Carlini <pcarlini@suse.de> | 2006-09-05 15:43:47 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2006-09-05 15:43:47 +0000 |
commit | 1a4ba99f961b372094ba2b5ee82057e57207ead0 (patch) | |
tree | ee25ea0ce6d5c9940de5e66b40863fce4681ccae | |
parent | 575643d56cd35107e7352060f420e93eda8282d5 (diff) | |
download | gcc-1a4ba99f961b372094ba2b5ee82057e57207ead0.zip gcc-1a4ba99f961b372094ba2b5ee82057e57207ead0.tar.gz gcc-1a4ba99f961b372094ba2b5ee82057e57207ead0.tar.bz2 |
basic_string.tcc (find(const _CharT*, size_type, size_type)): Reimplement in terms of traits::eq and traits::compare.
2006-09-05 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.tcc (find(const _CharT*, size_type,
size_type)): Reimplement in terms of traits::eq and traits::compare.
* include/ext/vstring.tcc (find(const _CharT*, size_type,
size_type)): Likewise.
* src/string-inst.cc: Remove unneded std::search instantiation.
From-SVN: r116698
-rw-r--r-- | libstdc++-v3/ChangeLog | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.tcc | 22 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/vstring.tcc | 22 | ||||
-rw-r--r-- | libstdc++-v3/src/string-inst.cc | 6 |
4 files changed, 31 insertions, 27 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 563621e..6397850 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2006-09-05 Paolo Carlini <pcarlini@suse.de> + + * include/bits/basic_string.tcc (find(const _CharT*, size_type, + size_type)): Reimplement in terms of traits::eq and traits::compare. + * include/ext/vstring.tcc (find(const _CharT*, size_type, + size_type)): Likewise. + * src/string-inst.cc: Remove unneded std::search instantiation. + 2006-09-04 Benjamin Kosnik <bkoz@redhat.com> PR c++/28871 diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 6b21d83..048d0ce 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -1,6 +1,6 @@ // Components for manipulating sequences of characters -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -710,17 +710,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std) find(const _CharT* __s, size_type __pos, size_type __n) const { __glibcxx_requires_string_len(__s, __n); - size_type __ret = npos; const size_type __size = this->size(); - if (__pos + __n <= __size) - { - const _CharT* __data = _M_data(); - const _CharT* __p = std::search(__data + __pos, __data + __size, - __s, __s + __n, traits_type::eq); - if (__p != __data + __size || __n == 0) - __ret = __p - __data; - } - return __ret; + const _CharT* __data = _M_data(); + + if (__n == 0) + return __pos <= __size ? __pos : npos; + + for (; __pos + __n <= __size; ++__pos) + if (traits_type::eq(__data[__pos], __s[0]) + && traits_type::compare(__data + __pos + 1, __s + 1, __n - 1) == 0) + return __pos; + return npos; } template<typename _CharT, typename _Traits, typename _Alloc> diff --git a/libstdc++-v3/include/ext/vstring.tcc b/libstdc++-v3/include/ext/vstring.tcc index 3ce552a..5196d10 100644 --- a/libstdc++-v3/include/ext/vstring.tcc +++ b/libstdc++-v3/include/ext/vstring.tcc @@ -1,6 +1,6 @@ // Versatile string -*- C++ -*- -// Copyright (C) 2005 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006 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 @@ -271,17 +271,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) find(const _CharT* __s, size_type __pos, size_type __n) const { __glibcxx_requires_string_len(__s, __n); - size_type __ret = npos; const size_type __size = this->size(); - if (__pos + __n <= __size) - { - const _CharT* __data = this->_M_data(); - const _CharT* __p = std::search(__data + __pos, __data + __size, - __s, __s + __n, traits_type::eq); - if (__p != __data + __size || __n == 0) - __ret = __p - __data; - } - return __ret; + const _CharT* __data = this->_M_data(); + + if (__n == 0) + return __pos <= __size ? __pos : npos; + + for (; __pos + __n <= __size; ++__pos) + if (traits_type::eq(__data[__pos], __s[0]) + && traits_type::compare(__data + __pos + 1, __s + 1, __n - 1) == 0) + return __pos; + return npos; } template<typename _CharT, typename _Traits, typename _Alloc, diff --git a/libstdc++-v3/src/string-inst.cc b/libstdc++-v3/src/string-inst.cc index 4c447e4..c17862b 100644 --- a/libstdc++-v3/src/string-inst.cc +++ b/libstdc++-v3/src/string-inst.cc @@ -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, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -77,10 +77,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) S::_S_construct(const C*, const C*, const allocator<C>&, forward_iterator_tag); - // Used in str::find. - template - const C* - search(const C*, const C*, const C*, const C*, bool(*)(const C&, const C&)); _GLIBCXX_END_NAMESPACE _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) |