-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] Refactor vector constructors to eliminate code duplication #113193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] Refactor vector constructors to eliminate code duplication #113193
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-libcxx Author: None (winner245) ChangesThis PR refactors the Full diff: https://github.com/llvm/llvm-project/pull/113193.diff 1 Files Affected:
diff --git a/libcxx/include/vector b/libcxx/include/vector
index dc31f31838264c..5ee2ca52752e23 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -1292,24 +1292,14 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_
template <class _Tp, class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) {
- auto __guard = std::__make_exception_guard(__destroy_vector(*this));
- if (__il.size() > 0) {
- __vallocate(__il.size());
- __construct_at_end(__il.begin(), __il.end(), __il.size());
- }
- __guard.__complete();
+ __init_with_size(__il.begin(), __il.end(), __il.size());
}
template <class _Tp, class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
: __alloc_(__a) {
- auto __guard = std::__make_exception_guard(__destroy_vector(*this));
- if (__il.size() > 0) {
- __vallocate(__il.size());
- __construct_at_end(__il.begin(), __il.end(), __il.size());
- }
- __guard.__complete();
+ __init_with_size(__il.begin(), __il.end(), __il.size());;
}
#endif // _LIBCPP_CXX03_LANG
|
ldionne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with green CI. The code previously in vector(initializer_list) was an exact duplicate of __init_with_size().
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
|
Hi team, It looks like the checks were cancelled due to my recent push to fix clang-format issues. I apologize for the inconvenience. This is my very first contribution to the LLVM project. Could someone please help me to re-trigger the checks? I appreciate all your help. Thanks in advance, |
|
@winner245 LLVM has a requirement that each commit is associated to a valid e-mail address. Can you please uncheck the "hide my email" option from your Github preferences? |
|
Hi @ldionne and team, I have unckecked "hide my email" in my settings. Please let me know if there is anything else from my side. I would also like to take this opportunity to express my sincere gratitude for all your invaluable guidance and help throughout this entire process. Though it’s a small step, it truly means a lot to me. I’m eager to continue contributing on this great journey and look forward to learning more from you in the future. Thank you so much for your help! Best regards, |
|
Thanks for your contribution! |
|
@winner245 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
This PR refactors the std::vector's initializer_list constructors to reduce code duplication.
The constructors now call
__init_with_sizedirectly, reducing code duplication and improvingreadability and maintainability.