[libcxx] Avoid intermediate string objects for substrings in windows operator/=

Check that appends with a path object doesn't do allocations, even
on windows.

Suggested by Marek in D98398. The patch might apply without D98398
(depending on how much of the diff context has to match), but doesn't
make much sense until after that patch has landed.

Differential Revision: https://reviews.llvm.org/D98412
This commit is contained in:
Martin Storsjö 2021-03-11 13:06:08 +02:00
parent cb2648e6f0
commit 49173ca4db
2 changed files with 11 additions and 2 deletions

View File

@ -1026,12 +1026,12 @@ public:
if (__p.has_root_directory()) {
path __root_name_str = root_name();
__pn_ = __root_name_str.native();
__pn_ += __p.__pn_.substr(__p_root_name_size);
__pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
return *this;
}
if (has_filename() || (!has_root_directory() && is_absolute()))
__pn_ += preferred_separator;
__pn_ += __p.__pn_.substr(__p_root_name_size);
__pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
return *this;
}
template <class _Source>

View File

@ -175,6 +175,15 @@ void doAppendSourceAllocTest(AppendOperatorTestcase const& TC)
}
assert(PathEq(LHS, E));
}
{
path LHS(L); PathReserve(LHS, ReserveSize);
path RHS(R);
{
DisableAllocationGuard g;
LHS /= RHS;
}
assert(PathEq(LHS, E));
}
// input iterator - For non-native char types, appends needs to copy the
// iterator range into a contiguous block of memory before it can perform the
// code_cvt conversions.