Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/string
Show First 20 Lines • Show All 790 Lines • ▼ Show 20 Lines | public: | ||||
_LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a) | _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a) | ||||
#if _LIBCPP_STD_VER <= 14 | #if _LIBCPP_STD_VER <= 14 | ||||
_NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); | ||||
#else | #else | ||||
_NOEXCEPT; | _NOEXCEPT; | ||||
#endif | #endif | ||||
// Optimization opportunity: do not externally instantiate the copy | |||||
// constructor, which inlines short string initialization. Long string | |||||
// initialization is delegated to the (external) __init_long()method, | |||||
// which results in a 3X-4X speed up for SSO initialization. | |||||
basic_string(const basic_string& __str); | basic_string(const basic_string& __str); | ||||
basic_string(const basic_string& __str, const allocator_type& __a); | basic_string(const basic_string& __str, const allocator_type& __a); | ||||
#ifndef _LIBCPP_CXX03_LANG | #ifndef _LIBCPP_CXX03_LANG | ||||
_LIBCPP_INLINE_VISIBILITY | _LIBCPP_INLINE_VISIBILITY | ||||
basic_string(basic_string&& __str) | basic_string(basic_string&& __str) | ||||
#if _LIBCPP_STD_VER <= 14 | #if _LIBCPP_STD_VER <= 14 | ||||
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | #ifndef _LIBCPP_CXX03_LANG | ||||
basic_string(initializer_list<_CharT> __il, const _Allocator& __a); | basic_string(initializer_list<_CharT> __il, const _Allocator& __a); | ||||
#endif // _LIBCPP_CXX03_LANG | #endif // _LIBCPP_CXX03_LANG | ||||
inline ~basic_string(); | inline ~basic_string(); | ||||
_LIBCPP_INLINE_VISIBILITY | _LIBCPP_INLINE_VISIBILITY | ||||
operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } | operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } | ||||
// Optimization opportunity: do not externally instantiate | |||||
basic_string& operator=(const basic_string& __str); | basic_string& operator=(const basic_string& __str); | ||||
template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type> | template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type> | ||||
basic_string& operator=(const _Tp& __t) | basic_string& operator=(const _Tp& __t) | ||||
{__self_view __sv = __t; return assign(__sv);} | {__self_view __sv = __t; return assign(__sv);} | ||||
#ifndef _LIBCPP_CXX03_LANG | #ifndef _LIBCPP_CXX03_LANG | ||||
_LIBCPP_INLINE_VISIBILITY | _LIBCPP_INLINE_VISIBILITY | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | #endif | ||||
template <class _Tp> | template <class _Tp> | ||||
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS | ||||
typename enable_if | typename enable_if | ||||
< | < | ||||
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, | ||||
basic_string& | basic_string& | ||||
>::type | >::type | ||||
assign(const _Tp & __t, size_type __pos, size_type __n=npos); | assign(const _Tp & __t, size_type __pos, size_type __n=npos); | ||||
#ifdef _LIBCPP_ABI_PARTIALLY_INLINE_ASSIGN | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
basic_string& assign(const value_type* __s, size_type __n); | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
basic_string& assign(const value_type* __s); | |||||
#else | |||||
basic_string& assign(const value_type* __s, size_type __n); | basic_string& assign(const value_type* __s, size_type __n); | ||||
basic_string& assign(const value_type* __s); | basic_string& assign(const value_type* __s); | ||||
#endif | |||||
basic_string& assign(size_type __n, value_type __c); | basic_string& assign(size_type __n, value_type __c); | ||||
template<class _InputIterator> | template<class _InputIterator> | ||||
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS | ||||
typename enable_if | typename enable_if | ||||
< | < | ||||
__is_exactly_cpp17_input_iterator<_InputIterator>::value | __is_exactly_cpp17_input_iterator<_InputIterator>::value | ||||
|| !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, | || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, | ||||
basic_string& | basic_string& | ||||
▲ Show 20 Lines • Show All 441 Lines • ▼ Show 20 Lines | #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT | ||||
inline | inline | ||||
void __init(const value_type* __s, size_type __sz, size_type __reserve); | void __init(const value_type* __s, size_type __sz, size_type __reserve); | ||||
inline | inline | ||||
void __init(const value_type* __s, size_type __sz); | void __init(const value_type* __s, size_type __sz); | ||||
inline | inline | ||||
void __init(size_type __n, value_type __c); | void __init(size_type __n, value_type __c); | ||||
void __init_long(const basic_string& __str); | |||||
template <class _InputIterator> | template <class _InputIterator> | ||||
inline | inline | ||||
typename enable_if | typename enable_if | ||||
< | < | ||||
__is_exactly_cpp17_input_iterator<_InputIterator>::value, | __is_exactly_cpp17_input_iterator<_InputIterator>::value, | ||||
void | void | ||||
>::type | >::type | ||||
__init(_InputIterator __first, _InputIterator __last); | __init(_InputIterator __first, _InputIterator __last); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | void __copy_assign_alloc(const basic_string& __str, true_type) | ||||
} | } | ||||
} | } | ||||
} | } | ||||
_LIBCPP_INLINE_VISIBILITY | _LIBCPP_INLINE_VISIBILITY | ||||
void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT | void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT | ||||
{} | {} | ||||
#ifdef _LIBCPP_ABI_PARTIALLY_INLINE_ASSIGN | |||||
basic_string& __assign(const value_type* __s, size_type __n); | |||||
basic_string& __assign(const value_type* __s); | |||||
#else | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
basic_string& __assign(const value_type* __s, size_type __n); | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
basic_string& __assign(const value_type* __s); | |||||
#endif | |||||
#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
basic_string& __assign_in_place(const value_type* __s, size_type __n); | |||||
#endif | |||||
#ifndef _LIBCPP_CXX03_LANG | #ifndef _LIBCPP_CXX03_LANG | ||||
_LIBCPP_INLINE_VISIBILITY | _LIBCPP_INLINE_VISIBILITY | ||||
void __move_assign(basic_string& __str, false_type) | void __move_assign(basic_string& __str, false_type) | ||||
_NOEXCEPT_(__alloc_traits::is_always_equal::value); | _NOEXCEPT_(__alloc_traits::is_always_equal::value); | ||||
_LIBCPP_INLINE_VISIBILITY | _LIBCPP_INLINE_VISIBILITY | ||||
void __move_assign(basic_string& __str, true_type) | void __move_assign(basic_string& __str, true_type) | ||||
#if _LIBCPP_STD_VER > 14 | #if _LIBCPP_STD_VER > 14 | ||||
_NOEXCEPT; | _NOEXCEPT; | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | else | ||||
__set_long_cap(__cap+1); | __set_long_cap(__cap+1); | ||||
__set_long_size(__sz); | __set_long_size(__sz); | ||||
} | } | ||||
traits_type::copy(_VSTD::__to_address(__p), __s, __sz); | traits_type::copy(_VSTD::__to_address(__p), __s, __sz); | ||||
traits_type::assign(__p[__sz], value_type()); | traits_type::assign(__p[__sz], value_type()); | ||||
} | } | ||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
void basic_string<_CharT, _Traits, _Allocator>::__init_long( | |||||
const basic_string& __str) { | |||||
const value_type* __s = _VSTD::__to_address(__str.__get_long_pointer()); | |||||
size_type __sz = __str.__get_long_size(); | |||||
size_type __cap = __recommend(__sz); | |||||
pointer __p = __alloc_traits::allocate(__alloc(), __cap + 1); | |||||
__set_long_pointer(__p); | |||||
__set_long_cap(__cap + 1); | |||||
__set_long_size(__sz); | |||||
traits_type::copy(_VSTD::__to_address(__p), __s, __sz); | |||||
traits_type::assign(__p[__sz], value_type()); | |||||
} | |||||
template <class _CharT, class _Traits, class _Allocator> | |||||
template <class> | template <class> | ||||
basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) | ||||
: __r_(__default_init_tag(), __a) | : __r_(__default_init_tag(), __a) | ||||
{ | { | ||||
_LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); | ||||
__init(__s, traits_type::length(__s)); | __init(__s, traits_type::length(__s)); | ||||
#if _LIBCPP_DEBUG_LEVEL >= 2 | #if _LIBCPP_DEBUG_LEVEL >= 2 | ||||
__get_db()->__insert_c(this); | __get_db()->__insert_c(this); | ||||
Show All 26 Lines | |||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) | ||||
: __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) | : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) | ||||
{ | { | ||||
if (!__str.__is_long()) | if (!__str.__is_long()) | ||||
__r_.first().__r = __str.__r_.first().__r; | __r_.first().__r = __str.__r_.first().__r; | ||||
else | else | ||||
__init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); | __init_long(__str); | ||||
#if _LIBCPP_DEBUG_LEVEL >= 2 | #if _LIBCPP_DEBUG_LEVEL >= 2 | ||||
__get_db()->__insert_c(this); | __get_db()->__insert_c(this); | ||||
#endif | #endif | ||||
} | } | ||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
basic_string<_CharT, _Traits, _Allocator>::basic_string( | basic_string<_CharT, _Traits, _Allocator>::basic_string( | ||||
const basic_string& __str, const allocator_type& __a) | const basic_string& __str, const allocator_type& __a) | ||||
: __r_(__default_init_tag(), __a) | : __r_(__default_init_tag(), __a) | ||||
{ | { | ||||
if (!__str.__is_long()) | if (!__str.__is_long()) | ||||
__r_.first().__r = __str.__r_.first().__r; | __r_.first().__r = __str.__r_.first().__r; | ||||
else | else | ||||
__init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); | __init_long(__str); | ||||
#if _LIBCPP_DEBUG_LEVEL >= 2 | #if _LIBCPP_DEBUG_LEVEL >= 2 | ||||
__get_db()->__insert_c(this); | __get_db()->__insert_c(this); | ||||
#endif | #endif | ||||
} | } | ||||
#ifndef _LIBCPP_CXX03_LANG | #ifndef _LIBCPP_CXX03_LANG | ||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
▲ Show 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | if (__old_cap+1 != __min_cap) | ||||
__alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); | ||||
__set_long_pointer(__p); | __set_long_pointer(__p); | ||||
__set_long_cap(__cap+1); | __set_long_cap(__cap+1); | ||||
} | } | ||||
// assign | // assign | ||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
inline | |||||
basic_string<_CharT, _Traits, _Allocator>& | basic_string<_CharT, _Traits, _Allocator>& | ||||
basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) | basic_string<_CharT, _Traits, _Allocator>::__assign_in_place( | ||||
const value_type* __s, size_type __n) { | |||||
pointer __p; | |||||
if (__is_long()) { | |||||
__p = __get_long_pointer(); | |||||
__set_long_size(__n); | |||||
} else { | |||||
__p = __get_short_pointer(); | |||||
__set_short_size(__n); | |||||
} | |||||
traits_type::copy(_VSTD::__to_address(__p), __s, __n); | |||||
traits_type::assign(__p[__n], value_type()); | |||||
__invalidate_iterators_past(__n); | |||||
return *this; | |||||
} | |||||
template <class _CharT, class _Traits, class _Allocator> | |||||
basic_string<_CharT, _Traits, _Allocator>& | |||||
basic_string<_CharT, _Traits, _Allocator>::__assign(const value_type* __s, size_type __n) | |||||
{ | { | ||||
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); | |||||
size_type __cap = capacity(); | size_type __cap = capacity(); | ||||
if (__cap >= __n) | if (__cap >= __n) | ||||
{ | { | ||||
value_type* __p = _VSTD::__to_address(__get_pointer()); | value_type* __p = _VSTD::__to_address(__get_pointer()); | ||||
traits_type::move(__p, __s, __n); | traits_type::move(__p, __s, __n); | ||||
traits_type::assign(__p[__n], value_type()); | traits_type::assign(__p[__n], value_type()); | ||||
__set_size(__n); | __set_size(__n); | ||||
__invalidate_iterators_past(__n); | __invalidate_iterators_past(__n); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
size_type __sz = size(); | size_type __sz = size(); | ||||
__grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); | __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); | ||||
} | } | ||||
return *this; | return *this; | ||||
} | } | ||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
basic_string<_CharT, _Traits, _Allocator>& | basic_string<_CharT, _Traits, _Allocator>& | ||||
basic_string<_CharT, _Traits, _Allocator>::__assign(const value_type* __s) | |||||
{ | |||||
return __assign(__s, traits_type::length(__s)); | |||||
} | |||||
template <class _CharT, class _Traits, class _Allocator> | |||||
basic_string<_CharT, _Traits, _Allocator>& | |||||
basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) { | |||||
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); | |||||
#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P | |||||
if (__builtin_constant_p(__n) && __n < __min_cap) { | |||||
return __assign_in_place(__s, __n); | |||||
} | |||||
#endif | |||||
return __assign(__s, __n); | |||||
} | |||||
template <class _CharT, class _Traits, class _Allocator> | |||||
basic_string<_CharT, _Traits, _Allocator>& | |||||
basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) | basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) | ||||
{ | { | ||||
size_type __cap = capacity(); | size_type __cap = capacity(); | ||||
if (__cap < __n) | if (__cap < __n) | ||||
{ | { | ||||
size_type __sz = size(); | size_type __sz = size(); | ||||
__grow_by(__cap, __n - __cap, __sz, 0, __sz); | __grow_by(__cap, __n - __cap, __sz, 0, __sz); | ||||
} | } | ||||
Show All 29 Lines | |||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
basic_string<_CharT, _Traits, _Allocator>& | basic_string<_CharT, _Traits, _Allocator>& | ||||
basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) | basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) | ||||
{ | { | ||||
if (this != &__str) | if (this != &__str) | ||||
{ | { | ||||
__copy_assign_alloc(__str); | __copy_assign_alloc(__str); | ||||
if (__is_long() | __str.__is_long()) { // LINT: explicit binary or. | |||||
return assign(__str.data(), __str.size()); | return assign(__str.data(), __str.size()); | ||||
} | } | ||||
__r_.first().__r = __str.__r_.first().__r; | |||||
} | |||||
return *this; | return *this; | ||||
} | } | ||||
#ifndef _LIBCPP_CXX03_LANG | #ifndef _LIBCPP_CXX03_LANG | ||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
inline | inline | ||||
void | void | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
basic_string<_CharT, _Traits, _Allocator>& | basic_string<_CharT, _Traits, _Allocator>& | ||||
basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) | basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) | ||||
{ | { | ||||
_LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); | _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); | ||||
return assign(__s, traits_type::length(__s)); | #ifdef _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P | ||||
if (__builtin_constant_p(__s[0]) && traits_type::length(__s) < __min_cap) { | |||||
return __assign_in_place(__s, traits_type::length(__s)); | |||||
} | |||||
#endif | |||||
return __assign(__s); | |||||
} | } | ||||
// append | // append | ||||
template <class _CharT, class _Traits, class _Allocator> | template <class _CharT, class _Traits, class _Allocator> | ||||
basic_string<_CharT, _Traits, _Allocator>& | basic_string<_CharT, _Traits, _Allocator>& | ||||
basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) | basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,972 Lines • Show Last 20 Lines |