From a55333003d33ceb5857c315093bdd7e58af4ee92 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 31 Oct 2016 02:46:25 +0000 Subject: Optimize filesystem::path by providing weaker exception guarantees. path uses string::append to construct, append, and concatenate paths. Unfortunatly string::append has a strong exception safety guaranteed and if it can't prove that the iterator operations don't throw then it will allocate a temporary string copy to append to. However this extra allocation and copy is very undesirable for path which doesn't have the same exception guarantees. To work around this this patch adds string::__append_forward_unsafe which exposes the std::string::append interface for forward iterators without enforcing that the iterator is noexcept. llvm-svn: 285532 --- libcxx/include/experimental/filesystem | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'libcxx/include/experimental/filesystem') diff --git a/libcxx/include/experimental/filesystem b/libcxx/include/experimental/filesystem index c674a03695f..410235f11a3 100644 --- a/libcxx/include/experimental/filesystem +++ b/libcxx/include/experimental/filesystem @@ -625,8 +625,18 @@ template <> struct _PathCVT { template - static void __append_range(string& __dest, _Iter __b, _Iter __e) { - __dest.append(__b, __e); + static typename enable_if< + __is_exactly_input_iterator<_Iter>::value + >::type __append_range(string& __dest, _Iter __b, _Iter __e) { + for (; __b != __e; ++__b) + __dest.push_back(*__b); + } + + template + static typename enable_if< + __is_forward_iterator<_Iter>::value + >::type __append_range(string& __dest, _Iter __b, _Iter __e) { + __dest.__append_forward_unsafe(__b, __e); } template -- cgit v1.2.3