-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] Simplify the implementation of string::{append,assign,assign_range} #162254
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
base: main
Are you sure you want to change the base?
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
8a83173
to
f0148e8
Compare
f0148e8
to
a54925e
Compare
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) Changes
Full diff: https://github.com/llvm/llvm-project/pull/162254.diff 1 Files Affected:
|
size_type __n = static_cast<size_type>(std::distance(__first, __last)); | ||
if (__n == 0) | ||
return *this; |
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.
This needs to move into the if
, or disappear entirely.
__grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0); | ||
__annotate_increase(__n); |
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.
I guess this could be something like
string __tmp;
__tmp.reserve(__sz + __n);
__tmp.assign(begin(), end());
__tmp.insert(__tmp.end(), __first, __last);
swap(*this, __tmp);
And then we don't have to care about __addr_in_range(*__first)
anymore. That's basically the algorithm that we do in vector
as well.
This can be done in a follow-up patch.
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s, size_type __n) | ||
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero"); | ||
_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); |
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.
Can we add a comment explaining what __string_is_trivial_iterator_v
represents? It was introduced in https://reviews.llvm.org/D98573.
__string_is_trivial_iterator_v
already implies that the iterator is contiguous. There is no need to specialize for input ranges specifically.