[libcxx-commits] [PATCH] D133661: [libc++] Improve binary size when using __transaction
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Sep 11 02:08:25 PDT 2022
philnik created this revision.
philnik added reviewers: ldionne, Mordante, var-const, huixie90.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133661
Files:
libcxx/include/__memory/uninitialized_algorithms.h
libcxx/include/__utility/transaction.h
Index: libcxx/include/__utility/transaction.h
===================================================================
--- libcxx/include/__utility/transaction.h
+++ libcxx/include/__utility/transaction.h
@@ -47,6 +47,8 @@
// return out;
// }
//
+
+#ifndef _LIBCPP_NO_EXCEPTIONS
template <class _Rollback>
struct __transaction {
__transaction() = delete;
@@ -85,6 +87,21 @@
_Rollback __rollback_;
bool __completed_;
};
+#else
+template <class _Rollback>
+struct __transaction {
+ __transaction() = delete;
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG __transaction(_Rollback) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG __transaction(__transaction&&)
+ _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value) {}
+ __transaction(const __transaction&) = delete;
+ __transaction& operator=(const __transaction&) = delete;
+ __transaction& operator=(__transaction&&) = delete;
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG void __complete() _NOEXCEPT {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG ~__transaction() {}
+};
+#endif
template <class _Rollback>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __transaction<_Rollback> __make_transaction(_Rollback __rollback) {
Index: libcxx/include/__memory/uninitialized_algorithms.h
===================================================================
--- libcxx/include/__memory/uninitialized_algorithms.h
+++ libcxx/include/__memory/uninitialized_algorithms.h
@@ -534,19 +534,14 @@
__uninitialized_allocator_copy(_Alloc& __alloc, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2) {
#ifndef _LIBCPP_NO_EXCEPTIONS
auto __destruct_first = __first2;
- try {
-#endif
+ auto __guard =
+ std::__make_transaction(_AllocatorDestroyRangeReverse<_Alloc, _Iter2>(__alloc, __destruct_first, __first2));
while (__first1 != __last1) {
allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__first2), *__first1);
++__first1;
++__first2;
}
-#ifndef _LIBCPP_NO_EXCEPTIONS
- } catch (...) {
- _AllocatorDestroyRangeReverse<_Alloc, _Iter2>(__alloc, __destruct_first, __first2)();
- throw;
- }
-#endif
+ __guard.__complete();
return __first2;
}
@@ -588,10 +583,9 @@
_Alloc& __alloc, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2) {
static_assert(__is_cpp17_move_insertable<_Alloc>::value,
"The specified type does not meet the requirements of Cpp17MoveInsertable");
-#ifndef _LIBCPP_NO_EXCEPTIONS
auto __destruct_first = __first2;
- try {
-#endif
+ auto __guard =
+ std::__make_transaction(_AllocatorDestroyRangeReverse<_Alloc, _Iter2>(__alloc, __destruct_first, __first2));
while (__first1 != __last1) {
#ifndef _LIBCPP_NO_EXCEPTIONS
allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__first2), std::move_if_noexcept(*__first1));
@@ -601,12 +595,7 @@
++__first1;
++__first2;
}
-#ifndef _LIBCPP_NO_EXCEPTIONS
- } catch (...) {
- _AllocatorDestroyRangeReverse<_Alloc, _Iter2>(__alloc, __destruct_first, __first2)();
- throw;
- }
-#endif
+ __guard.__complete();
return __first2;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133661.459339.patch
Type: text/x-patch
Size: 3193 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220911/59542485/attachment.bin>
More information about the libcxx-commits
mailing list