Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions libcxx/include/string
Original file line number Diff line number Diff line change
Expand Up @@ -1312,13 +1312,17 @@ public:
# if _LIBCPP_STD_VER >= 23
template <class _Op>
_LIBCPP_HIDE_FROM_ABI constexpr void resize_and_overwrite(size_type __n, _Op __op) {
__resize_default_init(__n);
__erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
size_type __sz = size();
size_type __cap = capacity();
if (__n > __cap)
__grow_by_without_replace(__cap, __n - __cap, __sz, __sz, 0);
__annotate_delete();
__set_size(__n);
__annotate_new(__n);
__erase_to_end(std::move(__op)(data(), auto(__n)));
}
# endif

_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __resize_default_init(size_type __n);

# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE)
_LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve() _NOEXCEPT { shrink_to_fit(); }
# endif
Expand Down Expand Up @@ -1410,8 +1414,6 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s);
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(size_type __n, value_type __c);

_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append_default_init(size_type __n);

template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
append(_InputIterator __first, _InputIterator __last) {
Expand Down Expand Up @@ -3079,22 +3081,6 @@ basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
return *this;
}

template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) {
if (__n == 0)
return;
size_type __cap = capacity();
size_type __sz = size();
if (__cap - __sz < __n)
__grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0);
__annotate_increase(__n);
pointer __p = __get_pointer();
__sz += __n;
__set_size(__sz);
traits_type::assign(__p[__sz], value_type());
}

template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) {
bool __is_short = !__is_long();
Expand Down Expand Up @@ -3433,16 +3419,6 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::re
__erase_to_end(__n);
}

template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 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>
_LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) {
if (__requested_capacity > max_size())
Expand Down
13 changes: 6 additions & 7 deletions libcxx/src/filesystem/format_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 0) string vformat_string(const ch

va_list apcopy;
va_copy(apcopy, ap);
int ret = ::vsnprintf(buf.data(), buf.size(), msg, apcopy);
int size = ::vsnprintf(buf.data(), buf.size(), msg, apcopy);
va_end(apcopy);

string result;
if (static_cast<size_t>(ret) < buf.size()) {
result.assign(buf.data(), static_cast<size_t>(ret));
if (static_cast<size_t>(size) < buf.size()) {
result.assign(buf.data(), static_cast<size_t>(size));
} else {
// we did not provide a long enough buffer on our first attempt. The
// return value is the number of bytes (excluding the null byte) that are
// needed for formatting.
size_t size_with_null = static_cast<size_t>(ret) + 1;
result.__resize_default_init(size_with_null - 1);
ret = ::vsnprintf(&result[0], size_with_null, msg, ap);
_LIBCPP_ASSERT_INTERNAL(static_cast<size_t>(ret) == (size_with_null - 1), "TODO");
result.resize_and_overwrite(size, [&](char* res, size_t n) { return ::vsnprintf(res, n, msg, ap); });
_LIBCPP_ASSERT_INTERNAL(static_cast<size_t>(size) == result.size(),
"vsnprintf did not result in the same number of characters as the first attempt?");
}
return result;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// UNSUPPORTED: availability-filesystem-missing
// UNSUPPORTED: no-filesystem
// ADDITIONAL_COMPILE_FLAGS: -I %{libcxx-dir}/src
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// UNSUPPORTED: availability-filesystem-missing

// <filesystem>
Expand Down

This file was deleted.

Loading