From e6ff2415adde6e708a1b9adf5f2c108d77ceb396 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Mon, 23 May 2016 21:45:33 +0200 Subject: [PATCH] rgw, optimization: reduce the overhead of RGWIdentityApplier::to_str(). Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_auth.cc | 42 +++++++++++++------------------------ src/rgw/rgw_auth.h | 10 +++++---- src/rgw/rgw_auth_decoimpl.h | 17 ++++++++------- 3 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/rgw/rgw_auth.cc b/src/rgw/rgw_auth.cc index 192f14e34daa2..9088fce7e23af 100644 --- a/src/rgw/rgw_auth.cc +++ b/src/rgw/rgw_auth.cc @@ -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, diff --git a/src/rgw/rgw_auth.h b/src/rgw/rgw_auth.h index 0bf39ec7faf3a..dd25a67fbe8f3 100644 --- a/src/rgw/rgw_auth.h +++ b/src/rgw/rgw_auth.h @@ -6,6 +6,7 @@ #define CEPH_RGW_AUTH_H #include +#include #include #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 @@ -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 { diff --git a/src/rgw/rgw_auth_decoimpl.h b/src/rgw/rgw_auth_decoimpl.h index 3a051e02b187f..fb232d91397d2 100644 --- a/src/rgw/rgw_auth_decoimpl.h +++ b/src/rgw/rgw_auth_decoimpl.h @@ -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 const rgw_user RGWThirdPartyAccountAuthApplier::UNKNOWN_ACCT; template -std::string RGWThirdPartyAccountAuthApplier::to_str() const +void RGWThirdPartyAccountAuthApplier::to_str(std::ostream& out) const { - return "RGWThirdPartyAccountAuthApplier(" + acct_user_override.to_str() + ")" - " -> " + RGWDecoratingAuthApplier::to_str(); + out << "RGWThirdPartyAccountAuthApplier(" + acct_user_override.to_str() + ")" + << " -> "; + RGWDecoratingAuthApplier::to_str(out); } template -- 2.39.5