LWG 2936: update path::compare logic and optimize string comparisons

Programming / Compilers / GCC - redi [138bc75d-0d04-0410-961f-82ee72b054a4] - 18 December 2018 15:52 EST

The resolution for LWG 2936 defines the comparison more precisely, which this patch implements. The patch also defines comparisons with strings to work without constructing a temporary path object (so avoids any memory allocations).

- include/bits/fs_path.h (path::compare(const string_type&)) (path::compare(const value_type*)): Add noexcept and construct a string view to compare to instead of a path. (path::compare(basic_string_view)): Add noexcept. Remove inline definition.
- src/filesystem/std-path.cc (path::_Parser): Track last type read from input. (path::_Parser::next()): Return a final empty component when the input ends in a non-root directory separator. (path::_M_append(basic_string_view)): Remove special cases for trailing non-root directory separator. (path::_M_concat(basic_string_view)): Likewise. (path::compare(const path&)): Implement LWG 2936. (path::compare(basic_string_view)): Define in terms of components returned by parser, consistent with LWG 2936.
- testsuite/27_io/filesystem/path/compare/lwg2936.cc: New.
- testsuite/27_io/filesystem/path/compare/path.cc: Test more cases.
- testsuite/27_io/filesystem/path/compare/strings.cc: Likewise.

b37e7cb040d LWG 2936: update path::compare logic and optimize string comparisons
libstdc++-v3/ChangeLog | 19 ++
libstdc++-v3/include/bits/fs_path.h | 16 +-
libstdc++-v3/src/filesystem/std-path.cc | 242 +++++++++++++++------
.../27_io/filesystem/path/compare/lwg2936.cc | 80 +++++++
.../27_io/filesystem/path/compare/path.cc | 11 +
.../27_io/filesystem/path/compare/strings.cc | 11 +
6 files changed, 300 insertions(+), 79 deletions(-)

Upstream: gcc.gnu.org


  • Share