pitrou commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4006553808


##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
 };
 
 template <template <typename...> class Cache, template <typename...> class 
MemoizerType,
-          typename Func, typename Key = 
std::decay_t<call_traits::argument_type<0, Func>>,
-          typename Value = std::decay_t<std::invoke_result_t<Func, const 
Key&>>,
-          typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, 
Func>,
-          typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t 
cache_capacity) {
+          typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+  using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+  using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+  using RetType = typename Memoizer::RetType;
+
   // std::function<> requires copy constructibility
   struct {
     RetType operator()(const Key& key) const { return (*memoized_)(key); }
     std::shared_ptr<Memoizer> memoized_;
   } shared_memoized = {
       std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
 
-  return shared_memoized;
+  return std::function<RetType(const Key&)>(std::move(shared_memoized));

Review Comment:
   Wrapping the result in a `std::function` adds a layer of indirection when 
calling `operator()` that might be expensive. Can we avoid this?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to