From d0cb5ac081635e9ae42f5facec36f753ed16c8eb Mon Sep 17 00:00:00 2001 From: Maxime Arthaud Date: Sat, 30 Sep 2023 05:36:30 -0700 Subject: [PATCH] Take function-like parameters as universal references Summary: There are a few cases where we were taking const references for function-like parameters. There is no real reason for that, let's just use universal references and be consistent with the rest of the codebase. Reviewed By: anwesht Differential Revision: D49771704 fbshipit-source-id: 77ae5332ecc73d48b071b4a8e70249bdca2ee9c4 --- include/sparta/FlatMap.h | 5 ++--- include/sparta/HashMap.h | 5 ++--- include/sparta/PatriciaTreeMap.h | 27 +++++++++++++++------------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/sparta/FlatMap.h b/include/sparta/FlatMap.h index 9bb609f..3ff87dd 100644 --- a/include/sparta/FlatMap.h +++ b/include/sparta/FlatMap.h @@ -259,7 +259,7 @@ class FlatMap final { // Requires CombiningFunction to coerce to // std::function template - void union_with(const CombiningFunction& combine, const FlatMap& other) { + void union_with(CombiningFunction&& combine, const FlatMap& other) { auto it = m_map.begin(), end = m_map.end(); auto other_it = other.m_map.begin(), other_end = other.m_map.end(); while (other_it != other_end) { @@ -284,8 +284,7 @@ class FlatMap final { // Requires CombiningFunction to coerce to // std::function template - void intersection_with(const CombiningFunction& combine, - const FlatMap& other) { + void intersection_with(CombiningFunction&& combine, const FlatMap& other) { auto it = m_map.begin(), end = m_map.end(); auto other_it = other.m_map.begin(), other_end = other.m_map.end(); while (it != end) { diff --git a/include/sparta/HashMap.h b/include/sparta/HashMap.h index 309a443..4a10140 100644 --- a/include/sparta/HashMap.h +++ b/include/sparta/HashMap.h @@ -242,7 +242,7 @@ class HashMap final { // Requires CombiningFunction to coerce to // std::function template - void union_with(const CombiningFunction& combine, const HashMap& other) { + void union_with(CombiningFunction&& combine, const HashMap& other) { for (const auto& other_binding : other.m_map) { auto binding = m_map.find(other_binding.first); if (binding == m_map.end()) { @@ -259,8 +259,7 @@ class HashMap final { // Requires CombiningFunction to coerce to // std::function template - void intersection_with(const CombiningFunction& combine, - const HashMap& other) { + void intersection_with(CombiningFunction&& combine, const HashMap& other) { auto it = m_map.begin(), end = m_map.end(); while (it != end) { auto other_binding = other.m_map.find(it->first); diff --git a/include/sparta/PatriciaTreeMap.h b/include/sparta/PatriciaTreeMap.h index 66ee99c..04bdfce 100644 --- a/include/sparta/PatriciaTreeMap.h +++ b/include/sparta/PatriciaTreeMap.h @@ -173,48 +173,51 @@ class PatriciaTreeMap final { // Requires CombiningFunction to coerce to // std::function template - PatriciaTreeMap& union_with(const CombiningFunction& combine, + PatriciaTreeMap& union_with(CombiningFunction&& combine, const PatriciaTreeMap& other) { - m_core.merge(apply_leafs(combine), other.m_core); + m_core.merge(apply_leafs(std::forward(combine)), + other.m_core); return *this; } template - PatriciaTreeMap& intersection_with(const CombiningFunction& combine, + PatriciaTreeMap& intersection_with(CombiningFunction&& combine, const PatriciaTreeMap& other) { - m_core.intersect(apply_leafs(combine), other.m_core); + m_core.intersect(apply_leafs(std::forward(combine)), + other.m_core); return *this; } // Requires that `combine(bottom, ...) = bottom`. template - PatriciaTreeMap& difference_with(const CombiningFunction& combine, + PatriciaTreeMap& difference_with(CombiningFunction&& combine, const PatriciaTreeMap& other) { - m_core.diff(apply_leafs(combine), other.m_core); + m_core.diff(apply_leafs(std::forward(combine)), + other.m_core); return *this; } template - PatriciaTreeMap get_union_with(const CombiningFunction& combine, + PatriciaTreeMap get_union_with(CombiningFunction&& combine, const PatriciaTreeMap& other) const { auto result = *this; - result.union_with(combine, other); + result.union_with(std::forward(combine), other); return result; } template - PatriciaTreeMap get_intersection_with(const CombiningFunction& combine, + PatriciaTreeMap get_intersection_with(CombiningFunction&& combine, const PatriciaTreeMap& other) const { auto result = *this; - result.intersection_with(combine, other); + result.intersection_with(std::forward(combine), other); return result; } template - PatriciaTreeMap get_difference_with(const CombiningFunction& combine, + PatriciaTreeMap get_difference_with(CombiningFunction&& combine, const PatriciaTreeMap& other) const { auto result = *this; - result.difference_with(combine, other); + result.difference_with(std::forward(combine), other); return result; }