From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Sun, 5 May 2024 17:16:30 +0000 (+0000) Subject: Maintenance: No ptr copy in future CredentialsCache::insert()s (#1807) X-Git-Tag: SQUID_7_0_1~125 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e5827d49897d63445b274025d1ab5acca60bb281;p=thirdparty%2Fsquid.git Maintenance: No ptr copy in future CredentialsCache::insert()s (#1807) Currently, the insert() method calls implicitly convert raw "this" pointers to RefCount pointers. That self-registration code raises red flags and may eventually be refactored. If it is refactored, insert() calls are likely to start using RefCount pointers as parameters. This change allows those future calls to avoid RefCount pointer copies. This change does not affect current calls performance. This change was triggered by Coverity CID 1554665: Unnecessary object copies can affect performance (COPY_INSTEAD_OF_MOVE). However, the insert() method is still calling RefCount copy assignment operator rather than its (cheaper) move assignment operator. Safely removing that overhead is only possible by reintroducing future parameter copying overhead described above _and_ using an explicit std::move() call that we are trying to avoid in general code. It is arguably not worth it. --- diff --git a/src/auth/CredentialsCache.cc b/src/auth/CredentialsCache.cc index 318e3092bf..506d7f4bd7 100644 --- a/src/auth/CredentialsCache.cc +++ b/src/auth/CredentialsCache.cc @@ -102,7 +102,7 @@ CredentialsCache::cleanup() } void -CredentialsCache::insert(const SBuf &userKey, Auth::User::Pointer anAuth_user) +CredentialsCache::insert(const SBuf &userKey, const Auth::User::Pointer &anAuth_user) { debugs(29, 6, "adding " << userKey << " (" << anAuth_user->username() << ")"); store_[userKey] = anAuth_user; diff --git a/src/auth/CredentialsCache.h b/src/auth/CredentialsCache.h index 6bfd57af23..d8ead0ee42 100644 --- a/src/auth/CredentialsCache.h +++ b/src/auth/CredentialsCache.h @@ -33,7 +33,7 @@ public: Auth::User::Pointer lookup(const SBuf &userKey) const; /// add an user to the cache with the provided key - void insert(const SBuf &userKey, Auth::User::Pointer anAuth_user); + void insert(const SBuf &userKey, const Auth::User::Pointer &anAuth_user); /// clear cache void reset() { store_.clear(); }