Skip to content

Commit

Permalink
[Test] Optimize directory indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Aug 16, 2024
1 parent e858e81 commit 1808276
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/internal/fsindexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ FilesystemIndexer::FilesystemIndexer( FilesystemItem directory,
}
}

inline auto countItemsInPath( const fs::path& path ) -> std::size_t {
std::error_code error;
auto begin = fs::recursive_directory_iterator{ path, fs::directory_options::skip_permission_denied, error };
return error ? 0 : static_cast< std::size_t >( std::distance( begin, fs::recursive_directory_iterator{} ) );
}

// NOTE: It indexes all the items whose metadata are needed in the archive to be created!
void FilesystemIndexer::listDirectoryItems( std::vector< std::unique_ptr< GenericInputItem > >& result,
bool recursive ) {
Expand All @@ -44,6 +50,7 @@ void FilesystemIndexer::listDirectoryItems( std::vector< std::unique_ptr< Generi

fs::path basePath = mDirItem.filesystemPath();
std::error_code error;
result.reserve( result.size() + countItemsInPath( basePath ) );
for ( auto iterator = fs::recursive_directory_iterator{ basePath, fs::directory_options::skip_permission_denied, error };
iterator != fs::recursive_directory_iterator{};
++iterator ) {
Expand Down

0 comments on commit 1808276

Please sign in to comment.