diff options
| author | Eric Fiselier <eric@efcs.ca> | 2018-11-26 20:15:38 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2018-11-26 20:15:38 +0000 |
| commit | 01a87ef88b77034ab6a9ea7bc9da24fb380e91e8 (patch) | |
| tree | 102226ac8c60dd336894950f571b5f4e48357c9b /libcxx/include/string | |
| parent | e8e8c5cf4dfb2cd8a2505db9d8d103661a153458 (diff) | |
| download | bcm5719-llvm-01a87ef88b77034ab6a9ea7bc9da24fb380e91e8.tar.gz bcm5719-llvm-01a87ef88b77034ab6a9ea7bc9da24fb380e91e8.zip | |
Add basic_string::__resize_default_init (from P1072)
This patch adds an implementation of __resize_default_init as
described in P1072R2. Additionally, it uses it in filesystem to
demonstrate its intended utility.
Once P1072 lands, or if it changes it's interface, I will adjust
the internal libc++ implementation to match.
llvm-svn: 347589
Diffstat (limited to 'libcxx/include/string')
| -rw-r--r-- | libcxx/include/string | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libcxx/include/string b/libcxx/include/string index 0c9f1cf1b2b..383b5c072ec 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -956,6 +956,8 @@ public: void resize(size_type __n, value_type __c); _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());} + _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n); + void reserve(size_type __res_arg = 0); _LIBCPP_INLINE_VISIBILITY void shrink_to_fit() _NOEXCEPT {reserve();} @@ -1010,6 +1012,10 @@ public: basic_string& append(const value_type* __s, size_type __n); basic_string& append(const value_type* __s); basic_string& append(size_type __n, value_type __c); + + _LIBCPP_INLINE_VISIBILITY + void __append_default_init(size_type __n); + template <class _ForwardIterator> _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator); @@ -2428,6 +2434,23 @@ basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) } template <class _CharT, class _Traits, class _Allocator> +inline void +basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) +{ + if (__n) + { + size_type __cap = capacity(); + size_type __sz = size(); + if (__cap - __sz < __n) + __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); + pointer __p = __get_pointer(); + __sz += __n; + __set_size(__sz); + traits_type::assign(__p[__sz], value_type()); + } +} + +template <class _CharT, class _Traits, class _Allocator> void basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) { @@ -3083,6 +3106,17 @@ basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) } template <class _CharT, class _Traits, class _Allocator> +inline void +basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n) +{ + size_type __sz = size(); + if (__n > __sz) { + __append_default_init(__n - __sz); + } else + __erase_to_end(__n); +} + +template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT |

