]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/common: avoid unnecessary throwing in stateful_error_t
authorRadosław Zarzyński <rzarzyns@redhat.com>
Wed, 30 Mar 2022 12:21:11 +0000 (14:21 +0200)
committerRadosław Zarzyński <rzarzyns@redhat.com>
Wed, 30 Mar 2022 12:21:25 +0000 (14:21 +0200)
This is an optimization for the flexible-but-slow `stateful_error_t`
error family of errorator. It's used infrequently.

Signed-off-by: Radosław Zarzyński <rzarzyns@redhat.com>
src/crimson/common/errorator.h

index 8472ad00eedfb7204227324dead4769d1efaa427..5f817eec918ee762395f6d5ad77348d3c61c90e2 100644 (file)
@@ -197,14 +197,13 @@ struct stateful_error_t : error_t<stateful_error_t<ErrorT>> {
     return [
       func = std::forward<Func>(func)
     ] (stateful_error_t<ErrorT>&& e) mutable -> decltype(auto) {
+      if constexpr (std::is_invocable_v<Func, void>) {
+        return std::invoke(std::forward<Func>(func));
+      }
       try {
         std::rethrow_exception(e.ep);
       } catch (const ErrorT& obj) {
-        if constexpr (std::is_invocable_v<Func, decltype(obj)>) {
-          return std::invoke(std::forward<Func>(func), obj);
-        } else {
-          return std::invoke(std::forward<Func>(func));
-        }
+        return std::invoke(std::forward<Func>(func), obj);
       }
       ceph_abort_msg("exception type mismatch -- impossible!");
     };