]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw, optimization: reduce the overhead of RGWIdentityApplier::to_str().
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 23 May 2016 19:45:33 +0000 (21:45 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 2 Jun 2016 19:17:13 +0000 (21:17 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_auth.cc
src/rgw/rgw_auth.h
src/rgw/rgw_auth_decoimpl.h

index 192f14e34daa21459e4e9fa4d16e297df8810ed3..9088fce7e23afa2a138fff0eb67e5375b6c65090 100644 (file)
@@ -56,14 +56,10 @@ rgw_auth_transform_old_authinfo(req_state * const s)
       return perm_mask;
     }
 
-    std::string to_str() const {
-      std::stringstream ss;
-
-      ss << "RGWDummyIdentityApplier(auth_id=" << id
-         << ", perm_mask=" << perm_mask
-         << ", is_admin=" << is_admin << ")";
-
-      return ss.str();
+    void to_str(std::ostream& out) const {
+      out << "RGWDummyIdentityApplier(auth_id=" << id
+          << ", perm_mask=" << perm_mask
+          << ", is_admin=" << is_admin << ")";
     }
   };
 
@@ -140,16 +136,12 @@ bool RGWRemoteAuthApplier::is_owner_of(const rgw_user& uid) const
   return info.acct_user == uid;
 }
 
-std::string RGWRemoteAuthApplier::to_str() const
+void RGWRemoteAuthApplier::to_str(std::ostream& out) const
 {
-  std::stringstream ss;
-
-  ss << "RGWRemoteAuthApplier(acct_user=" << info.acct_user
-     << ", acct_name=" << info.acct_name
-     << ", perm_mask=" << info.perm_mask
-     << ", is_admin=" << info.is_admin << ")";
-
-  return ss.str();
+  out << "RGWRemoteAuthApplier(acct_user=" << info.acct_user
+      << ", acct_name=" << info.acct_name
+      << ", perm_mask=" << info.perm_mask
+      << ", is_admin=" << info.is_admin << ")";
 }
 
 void RGWRemoteAuthApplier::create_account(const rgw_user& acct_user,
@@ -231,17 +223,13 @@ bool RGWLocalAuthApplier::is_owner_of(const rgw_user& uid) const
   return uid == user_info.user_id;
 }
 
-std::string RGWLocalAuthApplier::to_str() const
+void RGWLocalAuthApplier::to_str(std::ostream& out) const
 {
-  std::stringstream ss;
-
-  ss << "RGWLocalAuthApplier(acct_user=" << user_info.user_id
-     << ", acct_name=" << user_info.display_name
-     << ", subuser=" << subuser
-     << ", perm_mask=" << get_perm_mask()
-     << ", is_admin=" << user_info.admin << ")";
-
-  return ss.str();
+  out << "RGWLocalAuthApplier(acct_user=" << user_info.user_id
+      << ", acct_name=" << user_info.display_name
+      << ", subuser=" << subuser
+      << ", perm_mask=" << get_perm_mask()
+      << ", is_admin=" << user_info.admin << ")";
 }
 
 uint32_t RGWLocalAuthApplier::get_perm_mask(const std::string& subuser_name,
index 0bf39ec7faf3a80679204450f61a874e59a395db..dd25a67fbe8f37cb4156953b05a428912cd1b94c 100644 (file)
@@ -6,6 +6,7 @@
 #define CEPH_RGW_AUTH_H
 
 #include <functional>
+#include <ostream>
 #include <type_traits>
 
 #include "rgw_common.h"
@@ -50,12 +51,13 @@ public:
     return is_owner_of(rgw_user(RGW_USER_ANON_ID));
   }
 
-  virtual std::string to_str() const = 0;
+  virtual void to_str(std::ostream& out) const = 0;
 };
 
 inline std::ostream& operator<<(std::ostream& out,
                                 const RGWIdentityApplier &id) {
-  return out << id.to_str();
+  id.to_str(out);
+  return out;
 }
 
 std::unique_ptr<RGWIdentityApplier>
@@ -160,7 +162,7 @@ public:
   bool is_admin_of(const rgw_user& uid) const override;
   bool is_owner_of(const rgw_user& uid) const override;
   uint32_t get_perm_mask() const override { return info.perm_mask; }
-  std::string to_str() const override;
+  void to_str(std::ostream& out) const override;
   void load_acct_info(RGWUserInfo& user_info) const override; /* out */
 
   struct Factory {
@@ -205,7 +207,7 @@ public:
   uint32_t get_perm_mask() const override {
     return get_perm_mask(subuser, user_info);
   }
-  std::string to_str() const override;
+  void to_str(std::ostream& out) const override;
   void load_acct_info(RGWUserInfo& user_info) const override; /* out */
 
   struct Factory {
index 3a051e02b187fd3a45e31bda4cc21c71b2fa4832..fb232d91397d285dbb32b1cea4f1a1cf7088a73e 100644 (file)
@@ -37,8 +37,8 @@ public:
     return decoratee.get_perm_mask();
   }
 
-  virtual std::string to_str() const override {
-    return decoratee.to_str();
+  virtual void to_str(std::ostream& out) const override {
+    decoratee.to_str(out);
   }
 
   virtual void load_acct_info(RGWUserInfo& user_info) const override {  /* out */
@@ -79,8 +79,8 @@ public:
     return decoratee->get_perm_mask();
   }
 
-  virtual std::string to_str() const override {
-    return decoratee->to_str();
+  virtual void to_str(std::ostream& out) const override {
+    decoratee->to_str(out);
   }
 
   virtual void load_acct_info(RGWUserInfo& user_info) const override {  /* out */
@@ -110,7 +110,7 @@ public:
       acct_user_override(acct_user_override) {
   }
 
-  virtual std::string to_str() const override;
+  virtual void to_str(std::ostream& out) const override;
   virtual void load_acct_info(RGWUserInfo& user_info) const override;   /* out */
 };
 
@@ -119,10 +119,11 @@ template <typename T>
 const rgw_user RGWThirdPartyAccountAuthApplier<T>::UNKNOWN_ACCT;
 
 template <typename T>
-std::string RGWThirdPartyAccountAuthApplier<T>::to_str() const
+void RGWThirdPartyAccountAuthApplier<T>::to_str(std::ostream& out) const
 {
-  return "RGWThirdPartyAccountAuthApplier(" + acct_user_override.to_str() + ")"
-         " -> " + RGWDecoratingAuthApplier<T>::to_str();
+  out << "RGWThirdPartyAccountAuthApplier(" + acct_user_override.to_str() + ")"
+      <<   " -> ";
+  RGWDecoratingAuthApplier<T>::to_str(out);
 }
 
 template <typename T>