Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/string
Show First 20 Lines • Show All 792 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 | ||||
basic_string(const basic_string& __str); | basic_string(const basic_string& __str); | ||||
EricWF: This comment is a weird place. It's probably better suited on `__init_long` itself. | |||||
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 | ||||
Not Done ReplyInline ActionsNumbers never age well in comments. I would put them in the commit message instead. EricWF: Numbers never age well in comments. I would put them in the commit message instead. | |||||
Removed reference, it will pop in the commit once we do the inlining :) mvels: Removed reference, it will pop in the commit once we do the inlining :) | |||||
_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); | ||||
#else | #else | ||||
_NOEXCEPT; | _NOEXCEPT; | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 731 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); | ||||
// Identical to __init(s, sz), except that this function is always | |||||
The name of this function should express the intention that it's out-of-line and explicitly instantiated. Historically not much attention was paid to how std::string handled inlining and explicit instantiation, and now that we're fixing that I want to make it a clear part of any change. How about __init_long_out_of_line, __init_long_external, or __init_long_slow? EricWF: The name of this function should express the intention that it's out-of-line and explicitly… | |||||
// externally instantiated and not inlined: this function is the | |||||
// slow path for the (inlined) copy constructor. | |||||
void __init_long_external(const value_type* __s, size_type __sz); | |||||
template <class _InputIterator> | template <class _InputIterator> | ||||
inline | inline | ||||
_EnableIf | _EnableIf | ||||
< | < | ||||
__is_exactly_cpp17_input_iterator<_InputIterator>::value | __is_exactly_cpp17_input_iterator<_InputIterator>::value | ||||
> | > | ||||
__init(_InputIterator __first, _InputIterator __last); | __init(_InputIterator __first, _InputIterator __last); | ||||
▲ Show 20 Lines • Show All 233 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_external( | |||||
const _CharT* __s, size_type __sz) { | |||||
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_external(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); | ||||
#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_external(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); | ||||
#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 2,524 Lines • Show Last 20 Lines |
This comment is a weird place. It's probably better suited on __init_long itself.