Rewrite std::filesystem::path iterators and parser

This patch entirely rewrites the parsing logic for paths. Unlike the previous
implementation this one stores information about the current state; For example
if we are in a trailing separator or a root separator. This avoids the need for
extra lookahead (and extra work) when incrementing or decrementing an iterator.
Roughly this gives us a 15% speedup over the previous implementation.

Unfortunately this implementation is still a lot slower than libstdc++'s.
Because libstdc++ pre-parses and splits the path upon construction their
iterators are trivial to increment/decrement. This makes libc++ lazy parsing
100x slower than libstdc++. However the pre-parsing libstdc++ causes a ton
of extra and unneeded allocations when constructing the string. For example
`path("/foo/bar/")` would require at least 5 allocations with libstdc++
whereas libc++ uses only one. The non-allocating behavior is much preferable
when you consider filesystem usages like 'exists("/foo/bar/")'.

Even then libc++'s path seems to be twice as slow to simply construct compared
to libstdc++. More investigation is needed about this.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@285526 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2016-10-30 23:30:38 +00:00
parent 2d2f0c0af3
commit 271a19ec19
4 changed files with 402 additions and 261 deletions

View File

@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03
// UNSUPPORTED: libcpp-no-exceptions
// <experimental/filesystem>
// class path
#define _LIBCPP_DEBUG 0
#define _LIBCPP_ASSERT(cond, msg) ((cond) ? ((void)0) : throw 42)
#include <experimental/filesystem>
#include <iterator>
#include <type_traits>
#include <cassert>
#include "test_macros.h"
#include "filesystem_test_helper.hpp"
namespace fs = std::experimental::filesystem;
int main() {
using namespace fs;
// Test incrementing/decrementing a singular iterator
{
path::iterator singular;
try {
++singular;
assert(false);
} catch (int) {}
try {
--singular;
assert(false);
} catch (int) {}
}
// Test decrementing the begin iterator
{
path p("foo/bar");
auto it = p.begin();
try {
--it;
assert(false);
} catch (int) {}
++it;
++it;
try {
++it;
assert(false);
} catch (int) {}
}
// Test incrementing the end iterator
{
path p("foo/bar");
auto it = p.end();
try {
++it;
assert(false);
} catch (int) {}
--it;
--it;
try {
--it;
assert(false);
} catch (int) {}
}
}