summaryrefslogtreecommitdiffstats
path: root/libcxx/include/experimental/filesystem
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-10-30 23:53:50 +0000
committerEric Fiselier <eric@efcs.ca>2016-10-30 23:53:50 +0000
commitef915d3ef476f9de691300b6c6f9862b6b5607f8 (patch)
tree75869e0b7beb16030ce650e9538146d425e4d242 /libcxx/include/experimental/filesystem
parent299e67291c49cf28cf42e77b2ecdce1485a60ceb (diff)
downloadbcm5719-llvm-ef915d3ef476f9de691300b6c6f9862b6b5607f8.tar.gz
bcm5719-llvm-ef915d3ef476f9de691300b6c6f9862b6b5607f8.zip
Improve performance of constructing filesystem::path from strings.
This patch fixes a performance bug when constructing or appending to a path from a string or c-string. Previously we called 'push_back' to append every single character. This caused multiple re-allocation and copies when at most one reallocation is necessary. The new behavior is to simply call `string::append` so it can correctly handle reallocation. For large strings this change is a ~4x improvement. This also makes our path faster to construct than libstdc++'s. llvm-svn: 285530
Diffstat (limited to 'libcxx/include/experimental/filesystem')
-rw-r--r--libcxx/include/experimental/filesystem7
1 files changed, 4 insertions, 3 deletions
diff --git a/libcxx/include/experimental/filesystem b/libcxx/include/experimental/filesystem
index 1a8dee95c8b..c674a03695f 100644
--- a/libcxx/include/experimental/filesystem
+++ b/libcxx/include/experimental/filesystem
@@ -623,10 +623,10 @@ struct _PathCVT {
template <>
struct _PathCVT<char> {
+
template <class _Iter>
static void __append_range(string& __dest, _Iter __b, _Iter __e) {
- for (; __b != __e; ++__b)
- __dest.push_back(*__b);
+ __dest.append(__b, __e);
}
template <class _Iter>
@@ -640,7 +640,8 @@ struct _PathCVT<char> {
static void __append_source(string& __dest, _Source const& __s)
{
using _Traits = __is_pathable<_Source>;
- __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
+ __append_range(__dest, _Traits::__range_begin(__s),
+ _Traits::__range_end(__s));
}
};
OpenPOWER on IntegriCloud