Skip to content

Commit c18bcea

Browse files
<filesystem>: Improve symlink_status performance (#5071)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent 7657fb0 commit c18bcea

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

benchmarks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ add_benchmark(adjacent_difference src/adjacent_difference.cpp)
110110
add_benchmark(bitset_from_string src/bitset_from_string.cpp)
111111
add_benchmark(bitset_to_string src/bitset_to_string.cpp)
112112
add_benchmark(efficient_nonlocking_print src/efficient_nonlocking_print.cpp)
113+
add_benchmark(filesystem src/filesystem.cpp)
113114
add_benchmark(find_and_count src/find_and_count.cpp)
114115
add_benchmark(find_first_of src/find_first_of.cpp)
115116
add_benchmark(iota src/iota.cpp)

benchmarks/src/filesystem.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <benchmark/benchmark.h>
5+
#include <filesystem>
6+
#include <system_error>
7+
8+
void symlink_status(benchmark::State& state) {
9+
const auto path = std::filesystem::temp_directory_path();
10+
11+
for (auto _ : state) {
12+
std::error_code ec;
13+
benchmark::DoNotOptimize(path);
14+
const auto status = std::filesystem::symlink_status(path, ec);
15+
benchmark::DoNotOptimize(status);
16+
benchmark::DoNotOptimize(ec);
17+
}
18+
}
19+
20+
BENCHMARK(symlink_status);
21+
22+
BENCHMARK_MAIN();

stl/src/filesystem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,13 @@ namespace {
900900

901901
_Flags &= ~_Get_file_attributes_data;
902902
}
903+
904+
if (!_STD _Bitmask_includes_any(_Attributes, __std_fs_file_attr::_Reparse_point)
905+
&& _STD _Bitmask_includes_any(_Flags, __std_fs_stats_flags::_Reparse_tag)) {
906+
// if reparse tag is requested by caller but the file is not a reparse point, set tag to _None
907+
_Stats->_Reparse_point_tag = __std_fs_reparse_tag::_None;
908+
_Flags &= ~__std_fs_stats_flags::_Reparse_tag;
909+
}
903910
}
904911
}
905912

0 commit comments

Comments
 (0)