[libcxx-commits] [libcxx] [libc++] Refactor vector move constructor with allocator (PR #116449)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 15 21:47:57 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Peng Liu (winner245)
<details>
<summary>Changes</summary>
This PR simplifies the implementation of `std::vector` move constructor with alternative allocator by invoking `__init_with_size`, instead of calling `assign` which ultimately calls `__assign_with_size`. The advantage of using `__init_with_size` lies in its internal use of exception guard, thus simplifying the code. Furthermore, from a semantic standpoint, it is more intuitive for a constructor to call an _initialization_ function rather than an _assignment_ function.
---
Full diff: https://github.com/llvm/llvm-project/pull/116449.diff
1 Files Affected:
- (modified) libcxx/include/__vector/vector.h (+1-3)
``````````diff
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index d2d707d8c913c0..ac07750d8ece2f 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -976,9 +976,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_
__x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
} else {
typedef move_iterator<iterator> _Ip;
- auto __guard = std::__make_exception_guard(__destroy_vector(*this));
- assign(_Ip(__x.begin()), _Ip(__x.end()));
- __guard.__complete();
+ __init_with_size(_Ip(__x.begin()), _Ip(__x.end()), __x.size());
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/116449
More information about the libcxx-commits
mailing list