fix: forward forwarding-refs or change to const refs

This commit is contained in:
Marcus Holland-Moritz 2024-10-20 23:46:00 +02:00
parent 7a478e5623
commit 13b7175e9a
8 changed files with 18 additions and 16 deletions

View File

@ -58,7 +58,7 @@ template <typename T, typename U>
std::optional<bool> try_to(U&& s)
requires(std::same_as<T, bool> && std::is_arithmetic_v<U>)
{
return s != U{};
return std::forward<U>(s) != U{};
}
template <typename T>

View File

@ -92,7 +92,7 @@ class contextual_option {
template <typename T>
bool any_is(T&& pred) const {
for (auto e : contextual_) {
if (pred(e.second)) {
if (std::forward<T>(pred)(e.second)) {
return true;
}
}
@ -102,7 +102,7 @@ class contextual_option {
template <typename T>
void visit_contextual(T&& visitor) const {
for (auto const& [ctx, val] : contextual_) {
visitor(ctx, val);
std::forward<T>(visitor)(ctx, val);
}
}

View File

@ -80,7 +80,7 @@ class sortable_span {
: values_{values} {}
template <typename P>
void select(P&& predicate) {
void select(P const& predicate) {
index_.reserve(values_.size());
for (size_t i = 0; i < values_.size(); ++i) {
if (predicate(values_[i])) {

View File

@ -324,7 +324,8 @@ void analyze_frozen(std::ostream& os,
template <typename Function>
void parse_metadata_options(
MappedFrozen<thrift::metadata::metadata> const& meta, Function&& func) {
MappedFrozen<thrift::metadata::metadata> const& meta,
Function const& func) {
if (auto opt = meta.options()) {
func("mtime_only", opt->mtime_only());
func("packed_chunk_table", opt->packed_chunk_table());
@ -765,7 +766,7 @@ class metadata_ final : public metadata_v2::impl {
template <typename T>
void walk(uint32_t self_index, uint32_t parent_index, set_type<int>& seen,
T&& func) const;
T const& func) const;
template <typename T>
void walk_tree(T&& func) const {
@ -1557,7 +1558,7 @@ std::string metadata_<LoggerPolicy>::serialize_as_json(bool simple) const {
template <typename LoggerPolicy>
template <typename T>
void metadata_<LoggerPolicy>::walk(uint32_t self_index, uint32_t parent_index,
set_type<int>& seen, T&& func) const {
set_type<int>& seen, T const& func) const {
func(self_index, parent_index);
auto entry = make_dir_entry_view_impl(self_index, parent_index);

View File

@ -77,7 +77,7 @@ class file_scanner_ final : public file_scanner::impl {
void add_inode(file* p, int lineno);
template <typename Lookup>
void finalize_hardlinks(Lookup&& lookup);
void finalize_hardlinks(Lookup const& lookup);
template <bool UniqueOnly = false, typename KeyType>
void finalize_files(folly::F14FastMap<KeyType, inode::files_vector>& fmap,
@ -444,7 +444,7 @@ void file_scanner_<LoggerPolicy>::add_inode(file* p, int lineno) {
template <typename LoggerPolicy>
template <typename Lookup>
void file_scanner_<LoggerPolicy>::finalize_hardlinks(Lookup&& lookup) {
void file_scanner_<LoggerPolicy>::finalize_hardlinks(Lookup const& lookup) {
auto tv = LOG_TIMED_VERBOSE;
for (auto& kv : hardlinks_) {

View File

@ -384,7 +384,7 @@ class inode_ : public inode {
void scan_range(mmif* mm, scanner_progress* sprog, size_t offset, size_t size,
size_t chunk_size, T&& scanner) {
while (size >= chunk_size) {
scanner(mm->span(offset, chunk_size));
std::forward<T>(scanner)(mm->span(offset, chunk_size));
mm->release_until(offset);
offset += chunk_size;
size -= chunk_size;

View File

@ -95,8 +95,8 @@ int distance(std::array<uint64_t, 4> const& a, std::array<uint64_t, 4> const& b)
}
template <typename GetI, typename GetK, typename Swap>
void order_by_shortest_path(size_t count, GetI&& geti, GetK&& getk,
Swap&& swapper) {
void order_by_shortest_path(size_t count, GetI const& geti, GetK const& getk,
Swap const& swapper) {
for (size_t i = 0; i < count - 1; ++i) {
auto bi = geti(i);
int best_distance = std::numeric_limits<int>::max();

View File

@ -115,7 +115,8 @@ class fast_multimap {
}
template <typename F>
DWARFS_FORCE_INLINE void for_each_value(KeyT const& key, F&& func) const {
DWARFS_FORCE_INLINE void
for_each_value(KeyT const& key, F const& func) const {
if (auto it = values_.find(key); it != values_.end()) [[unlikely]] {
func(it->second);
if (auto it2 = collisions_.find(key); it2 != collisions_.end())
@ -128,7 +129,7 @@ class fast_multimap {
}
template <typename F>
DWARFS_FORCE_INLINE bool any_value_is(KeyT const& key, F&& func) const {
DWARFS_FORCE_INLINE bool any_value_is(KeyT const& key, F const& func) const {
if (auto it = values_.find(key); it != values_.end()) [[unlikely]] {
if (func(it->second)) {
return true;
@ -347,7 +348,7 @@ class ConstantGranularityPolicy : private GranularityPolicyBase {
}
template <typename T>
static DWARFS_FORCE_INLINE void for_bytes_in_frame(T&& func) {
static DWARFS_FORCE_INLINE void for_bytes_in_frame(T const& func) {
for (size_t i = 0; i < kGranularity; ++i) {
func();
}
@ -415,7 +416,7 @@ class VariableGranularityPolicy : private GranularityPolicyBase {
}
template <typename T>
DWARFS_FORCE_INLINE void for_bytes_in_frame(T&& func) const {
DWARFS_FORCE_INLINE void for_bytes_in_frame(T const& func) const {
for (size_t i = 0; i < granularity_; ++i) {
func();
}