mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 11:59:48 -04:00
refactor: use const refs where pass-by-value is unnecessary
This commit is contained in:
parent
fdddf95bfc
commit
d5df4f9deb
@ -31,7 +31,8 @@ namespace dwarfs::internal {
|
||||
class feature_set {
|
||||
public:
|
||||
static std::set<std::string> get_supported();
|
||||
static std::set<std::string> get_unsupported(std::set<std::string> features);
|
||||
static std::set<std::string>
|
||||
get_unsupported(std::set<std::string> const& wanted_features);
|
||||
|
||||
void add(feature f);
|
||||
|
||||
|
@ -86,7 +86,7 @@ bool parse_metadata_requirements_set(T& container, nlohmann::json& req,
|
||||
fmt::format("unexpected empty set for requirement '{}'", name));
|
||||
}
|
||||
|
||||
for (auto v : val[1]) {
|
||||
for (auto const& v : val[1]) {
|
||||
std::optional<typename T::value_type> maybe_value;
|
||||
|
||||
try {
|
||||
|
@ -51,7 +51,7 @@ std::set<std::string> feature_set::get_supported() {
|
||||
};
|
||||
|
||||
std::set<std::string>
|
||||
feature_set::get_unsupported(std::set<std::string> wanted_features) {
|
||||
feature_set::get_unsupported(std::set<std::string> const& wanted_features) {
|
||||
auto const supported_features = get_supported();
|
||||
std::set<std::string> missing;
|
||||
std::ranges::set_difference(wanted_features, supported_features,
|
||||
|
@ -163,7 +163,7 @@ class inode_reader_ final : public inode_reader_v2::impl {
|
||||
const StoreFunc& store) const;
|
||||
|
||||
void do_readahead(uint32_t inode, chunk_range::iterator it,
|
||||
chunk_range::iterator end, file_off_t read_offset,
|
||||
chunk_range::iterator const& end, file_off_t read_offset,
|
||||
size_t size, file_off_t it_offset) const;
|
||||
|
||||
block_cache cache_;
|
||||
@ -194,7 +194,7 @@ void inode_reader_<LoggerPolicy>::dump(std::ostream& os,
|
||||
template <typename LoggerPolicy>
|
||||
void inode_reader_<LoggerPolicy>::do_readahead(uint32_t inode,
|
||||
chunk_range::iterator it,
|
||||
chunk_range::iterator end,
|
||||
chunk_range::iterator const& end,
|
||||
file_off_t const read_offset,
|
||||
size_t const size,
|
||||
file_off_t it_offset) const {
|
||||
|
@ -564,7 +564,8 @@ class metadata_ final : public metadata_v2::impl {
|
||||
|
||||
void check_inode_size_cache() const;
|
||||
|
||||
file_stat getattr_impl(inode_view iv, getattr_options const& opts) const;
|
||||
file_stat
|
||||
getattr_impl(inode_view const& iv, getattr_options const& opts) const;
|
||||
|
||||
inode_view make_inode_view(uint32_t inode) const {
|
||||
// TODO: move compatibility details to metadata_types
|
||||
@ -654,7 +655,7 @@ class metadata_ final : public metadata_v2::impl {
|
||||
return {iv.inode_num(), global_};
|
||||
}
|
||||
|
||||
directory_view make_directory_view(inode_view iv) const {
|
||||
directory_view make_directory_view(inode_view const& iv) const {
|
||||
return make_directory_view(iv.raw());
|
||||
}
|
||||
|
||||
@ -662,15 +663,15 @@ class metadata_ final : public metadata_v2::impl {
|
||||
|
||||
// TODO: see if we really need to pass the extra dir_entry_view in
|
||||
// addition to directory_view
|
||||
void dump(std::ostream& os, const std::string& indent, dir_entry_view entry,
|
||||
fsinfo_options const& opts,
|
||||
void dump(std::ostream& os, const std::string& indent,
|
||||
dir_entry_view const& entry, fsinfo_options const& opts,
|
||||
std::function<void(const std::string&, uint32_t)> const& icb) const;
|
||||
void dump(std::ostream& os, const std::string& indent, directory_view dir,
|
||||
dir_entry_view entry, fsinfo_options const& opts,
|
||||
dir_entry_view const& entry, fsinfo_options const& opts,
|
||||
std::function<void(const std::string&, uint32_t)> const& icb) const;
|
||||
|
||||
nlohmann::json as_json(dir_entry_view entry) const;
|
||||
nlohmann::json as_json(directory_view dir, dir_entry_view entry) const;
|
||||
nlohmann::json as_json(dir_entry_view const& entry) const;
|
||||
nlohmann::json as_json(directory_view dir, dir_entry_view const& entry) const;
|
||||
|
||||
std::optional<dir_entry_view>
|
||||
find_impl(directory_view dir, auto const& range, auto const& name,
|
||||
@ -1180,7 +1181,7 @@ void metadata_<LoggerPolicy>::check_consistency() const {
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
void metadata_<LoggerPolicy>::dump(
|
||||
std::ostream& os, const std::string& indent, dir_entry_view entry,
|
||||
std::ostream& os, const std::string& indent, dir_entry_view const& entry,
|
||||
fsinfo_options const& opts,
|
||||
std::function<void(const std::string&, uint32_t)> const& icb) const {
|
||||
auto iv = entry.inode();
|
||||
@ -1355,7 +1356,7 @@ metadata_<LoggerPolicy>::info_as_json(fsinfo_options const& opts,
|
||||
template <typename LoggerPolicy>
|
||||
void metadata_<LoggerPolicy>::dump(
|
||||
std::ostream& os, const std::string& indent, directory_view dir,
|
||||
dir_entry_view entry, fsinfo_options const& opts,
|
||||
dir_entry_view const& entry, fsinfo_options const& opts,
|
||||
std::function<void(const std::string&, uint32_t)> const& icb) const {
|
||||
auto range = dir.entry_range();
|
||||
|
||||
@ -1515,8 +1516,9 @@ void metadata_<LoggerPolicy>::dump(
|
||||
}
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
nlohmann::json metadata_<LoggerPolicy>::as_json(directory_view dir,
|
||||
dir_entry_view entry) const {
|
||||
nlohmann::json
|
||||
metadata_<LoggerPolicy>::as_json(directory_view dir,
|
||||
dir_entry_view const& entry) const {
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
|
||||
auto range = dir.entry_range();
|
||||
@ -1529,7 +1531,8 @@ nlohmann::json metadata_<LoggerPolicy>::as_json(directory_view dir,
|
||||
}
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
nlohmann::json metadata_<LoggerPolicy>::as_json(dir_entry_view entry) const {
|
||||
nlohmann::json
|
||||
metadata_<LoggerPolicy>::as_json(dir_entry_view const& entry) const {
|
||||
nlohmann::json obj;
|
||||
|
||||
auto iv = entry.inode();
|
||||
@ -1882,7 +1885,7 @@ metadata_<LoggerPolicy>::find(int inode, std::string_view name) const {
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
file_stat
|
||||
metadata_<LoggerPolicy>::getattr_impl(inode_view iv,
|
||||
metadata_<LoggerPolicy>::getattr_impl(inode_view const& iv,
|
||||
getattr_options const& opts) const {
|
||||
file_stat stbuf;
|
||||
|
||||
|
@ -373,7 +373,7 @@ bool filesystem_extractor_<LoggerPolicy>::extract(
|
||||
});
|
||||
}
|
||||
|
||||
fs.walk_data_order([&](auto entry) {
|
||||
fs.walk_data_order([&](auto const& entry) {
|
||||
// TODO: we can surely early abort walk() somehow
|
||||
if (entry.is_root() || hard_error) {
|
||||
return;
|
||||
|
@ -278,13 +278,13 @@ class similarity_ordering_ final : public similarity_ordering::impl {
|
||||
basic_cluster_tree_node<
|
||||
basic_cluster<Bits, BitsType, CountsType, index_value_type>>& node,
|
||||
basic_array_similarity_element_view<Bits, BitsType> const& ev,
|
||||
std::shared_ptr<job_tracker> jt, int max_distance) const;
|
||||
std::shared_ptr<job_tracker> const& jt, int max_distance) const;
|
||||
|
||||
template <size_t Bits, typename BitsType, typename CountsType>
|
||||
void cluster(basic_cluster_tree_node<basic_cluster<Bits, BitsType, CountsType,
|
||||
index_value_type>>& root,
|
||||
basic_array_similarity_element_view<Bits, BitsType> const& ev,
|
||||
std::shared_ptr<job_tracker> jt) const;
|
||||
std::shared_ptr<job_tracker> const& jt) const;
|
||||
|
||||
template <size_t Bits, typename BitsType, typename CountsType>
|
||||
void collect_rec(
|
||||
@ -529,7 +529,7 @@ void similarity_ordering_<LoggerPolicy>::cluster_rec(
|
||||
basic_cluster_tree_node<
|
||||
basic_cluster<Bits, BitsType, CountsType, index_value_type>>& node,
|
||||
basic_array_similarity_element_view<Bits, BitsType> const& ev,
|
||||
std::shared_ptr<job_tracker> jt, int max_distance) const {
|
||||
std::shared_ptr<job_tracker> const& jt, int max_distance) const {
|
||||
cluster_by_distance(node, ev, max_distance);
|
||||
|
||||
for (auto& cn : node.children()) {
|
||||
@ -556,7 +556,7 @@ void similarity_ordering_<LoggerPolicy>::cluster(
|
||||
basic_cluster_tree_node<
|
||||
basic_cluster<Bits, BitsType, CountsType, index_value_type>>& root,
|
||||
basic_array_similarity_element_view<Bits, BitsType> const& ev,
|
||||
std::shared_ptr<job_tracker> jt) const {
|
||||
std::shared_ptr<job_tracker> const& jt) const {
|
||||
jt->start_job();
|
||||
wg_.add_job([this, &root, &ev, jt] {
|
||||
cluster_rec(root, ev, jt, Bits / 2);
|
||||
|
@ -319,12 +319,13 @@ class scanner_ final : public scanner::impl {
|
||||
progress& prog, file_scanner& fs);
|
||||
|
||||
std::shared_ptr<entry>
|
||||
add_entry(std::filesystem::path const& name, std::shared_ptr<dir> parent,
|
||||
progress& prog, file_scanner& fs, bool debug_filter = false);
|
||||
add_entry(std::filesystem::path const& name,
|
||||
std::shared_ptr<dir> const& parent, progress& prog,
|
||||
file_scanner& fs, bool debug_filter = false);
|
||||
|
||||
void dump_state(std::string_view env_var, std::string_view what,
|
||||
std::shared_ptr<file_access const> fa,
|
||||
std::function<void(std::ostream&)> dumper) const;
|
||||
std::shared_ptr<file_access const> const& fa,
|
||||
std::function<void(std::ostream&)> const& dumper) const;
|
||||
|
||||
LOG_PROXY_DECL(LoggerPolicy);
|
||||
worker_group& wg_;
|
||||
@ -367,8 +368,9 @@ FOLLY_GCC_DISABLE_WARNING("-Wnrvo")
|
||||
template <typename LoggerPolicy>
|
||||
std::shared_ptr<entry>
|
||||
scanner_<LoggerPolicy>::add_entry(std::filesystem::path const& name,
|
||||
std::shared_ptr<dir> parent, progress& prog,
|
||||
file_scanner& fs, bool debug_filter) {
|
||||
std::shared_ptr<dir> const& parent,
|
||||
progress& prog, file_scanner& fs,
|
||||
bool debug_filter) {
|
||||
try {
|
||||
auto pe = entry_factory_.create(os_, name, parent);
|
||||
|
||||
@ -496,8 +498,8 @@ FOLLY_POP_WARNING
|
||||
template <typename LoggerPolicy>
|
||||
void scanner_<LoggerPolicy>::dump_state(
|
||||
std::string_view env_var, std::string_view what,
|
||||
std::shared_ptr<file_access const> fa,
|
||||
std::function<void(std::ostream&)> dumper) const {
|
||||
std::shared_ptr<file_access const> const& fa,
|
||||
std::function<void(std::ostream&)> const& dumper) const {
|
||||
if (auto dumpfile = os_.getenv(env_var)) {
|
||||
if (fa) {
|
||||
LOG_VERBOSE << "dumping " << what << " to " << *dumpfile;
|
||||
@ -828,7 +830,7 @@ void scanner_<LoggerPolicy>::scan(
|
||||
meta);
|
||||
});
|
||||
|
||||
for (auto ino : span) {
|
||||
for (auto const& ino : span) {
|
||||
prog.current.store(ino.get());
|
||||
|
||||
// TODO: factor this code out
|
||||
|
@ -816,7 +816,7 @@ void op_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, file_off_t off,
|
||||
|
||||
checked_reply_err(log_, req, [&] {
|
||||
readdir_lowlevel_policy policy{req, ino, size};
|
||||
return op_readdir_common(userdata.fs, policy, off, [](auto) {});
|
||||
return op_readdir_common(userdata.fs, policy, off, [](auto const&) {});
|
||||
});
|
||||
}
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user