sso_string_base.h (__sso_string_base<>::_M_compare): Add...
2005-12-10 Paolo Carlini <pcarlini@suse.de> * include/ext/sso_string_base.h (__sso_string_base<>::_M_compare): Add, specialized for char and wchar_t to immediately return true when a string is compared to itself. * include/ext/rc_string_base.h (__rc_string_base<>::_M_compare): Likewise, for the same _Rep. * include/ext/vstring.h (compare(const string&)): Use it. * include/ext/sso_string_base.h (__sso_string_base<>::_M_destroy): Deallocate passed size + 1. (_M_dispose, _M_reserve): Adjust. From-SVN: r108372
This commit is contained in:
parent
42e25796b5
commit
b6105bf2c3
|
@ -1,3 +1,16 @@
|
||||||
|
2005-12-10 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
* include/ext/sso_string_base.h (__sso_string_base<>::_M_compare):
|
||||||
|
Add, specialized for char and wchar_t to immediately return true
|
||||||
|
when a string is compared to itself.
|
||||||
|
* include/ext/rc_string_base.h (__rc_string_base<>::_M_compare):
|
||||||
|
Likewise, for the same _Rep.
|
||||||
|
* include/ext/vstring.h (compare(const string&)): Use it.
|
||||||
|
|
||||||
|
* include/ext/sso_string_base.h (__sso_string_base<>::_M_destroy):
|
||||||
|
Deallocate passed size + 1.
|
||||||
|
(_M_dispose, _M_reserve): Adjust.
|
||||||
|
|
||||||
2005-12-09 Paolo Carlini <pcarlini@suse.de>
|
2005-12-09 Paolo Carlini <pcarlini@suse.de>
|
||||||
Howard Hinnant <hhinnant@apple.com>
|
Howard Hinnant <hhinnant@apple.com>
|
||||||
|
|
||||||
|
|
|
@ -334,6 +334,10 @@ namespace __gnu_cxx
|
||||||
|
|
||||||
void
|
void
|
||||||
_M_erase(size_type __pos, size_type __n);
|
_M_erase(size_type __pos, size_type __n);
|
||||||
|
|
||||||
|
bool
|
||||||
|
_M_compare(const __rc_string_base&) const
|
||||||
|
{ return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||||
|
@ -670,6 +674,28 @@ namespace __gnu_cxx
|
||||||
|
|
||||||
_M_rep()->_M_set_length(__new_size);
|
_M_rep()->_M_set_length(__new_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool
|
||||||
|
__rc_string_base<char, std::char_traits<char>,
|
||||||
|
std::allocator<char> >::
|
||||||
|
_M_compare(const __rc_string_base& __rcs) const
|
||||||
|
{
|
||||||
|
if (_M_rep() == __rcs._M_rep())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool
|
||||||
|
__rc_string_base<wchar_t, std::char_traits<wchar_t>,
|
||||||
|
std::allocator<wchar_t> >::
|
||||||
|
_M_compare(const __rc_string_base& __rcs) const
|
||||||
|
{
|
||||||
|
if (_M_rep() == __rcs._M_rep())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} // namespace __gnu_cxx
|
} // namespace __gnu_cxx
|
||||||
|
|
||||||
#endif /* _RC_STRING_BASE_H */
|
#endif /* _RC_STRING_BASE_H */
|
||||||
|
|
|
@ -102,7 +102,7 @@ namespace __gnu_cxx
|
||||||
_M_dispose()
|
_M_dispose()
|
||||||
{
|
{
|
||||||
if (!_M_is_local())
|
if (!_M_is_local())
|
||||||
_M_destroy(_M_allocated_capacity + 1);
|
_M_destroy(_M_allocated_capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -225,13 +225,17 @@ namespace __gnu_cxx
|
||||||
|
|
||||||
void
|
void
|
||||||
_M_erase(size_type __pos, size_type __n);
|
_M_erase(size_type __pos, size_type __n);
|
||||||
|
|
||||||
|
bool
|
||||||
|
_M_compare(const __sso_string_base&) const
|
||||||
|
{ return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||||
void
|
void
|
||||||
__sso_string_base<_CharT, _Traits, _Alloc>::
|
__sso_string_base<_CharT, _Traits, _Alloc>::
|
||||||
_M_destroy(size_type __size) throw()
|
_M_destroy(size_type __size) throw()
|
||||||
{ _CharT_alloc_type(_M_get_allocator()).deallocate(_M_data(), __size); }
|
{ _CharT_alloc_type(_M_get_allocator()).deallocate(_M_data(), __size + 1); }
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||||
void
|
void
|
||||||
|
@ -498,7 +502,7 @@ namespace __gnu_cxx
|
||||||
else if (!_M_is_local())
|
else if (!_M_is_local())
|
||||||
{
|
{
|
||||||
_S_copy(_M_local_data, _M_data(), _M_length() + 1);
|
_S_copy(_M_local_data, _M_data(), _M_length() + 1);
|
||||||
_M_destroy(__capacity + 1);
|
_M_destroy(__capacity);
|
||||||
_M_data(_M_local_data);
|
_M_data(_M_local_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -541,6 +545,28 @@ namespace __gnu_cxx
|
||||||
|
|
||||||
_M_set_length(_M_length() - __n);
|
_M_set_length(_M_length() - __n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool
|
||||||
|
__sso_string_base<char, std::char_traits<char>,
|
||||||
|
std::allocator<char> >::
|
||||||
|
_M_compare(const __sso_string_base& __rcs) const
|
||||||
|
{
|
||||||
|
if (this == &__rcs)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool
|
||||||
|
__sso_string_base<wchar_t, std::char_traits<wchar_t>,
|
||||||
|
std::allocator<wchar_t> >::
|
||||||
|
_M_compare(const __sso_string_base& __rcs) const
|
||||||
|
{
|
||||||
|
if (this == &__rcs)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} // namespace __gnu_cxx
|
} // namespace __gnu_cxx
|
||||||
|
|
||||||
#endif /* _SSO_STRING_BASE_H */
|
#endif /* _SSO_STRING_BASE_H */
|
||||||
|
|
|
@ -1665,6 +1665,9 @@ namespace __gnu_cxx
|
||||||
int
|
int
|
||||||
compare(const __versa_string& __str) const
|
compare(const __versa_string& __str) const
|
||||||
{
|
{
|
||||||
|
if (this->_M_compare(__str))
|
||||||
|
return 0;
|
||||||
|
|
||||||
const size_type __size = this->size();
|
const size_type __size = this->size();
|
||||||
const size_type __osize = __str.size();
|
const size_type __osize = __str.size();
|
||||||
const size_type __len = std::min(__size, __osize);
|
const size_type __len = std::min(__size, __osize);
|
||||||
|
|
Loading…
Reference in New Issue