]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Maintenance: No ptr copy in future CredentialsCache::insert()s (#1807)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Sun, 5 May 2024 17:16:30 +0000 (17:16 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sun, 5 May 2024 17:16:34 +0000 (17:16 +0000)
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.

src/auth/CredentialsCache.cc
src/auth/CredentialsCache.h

index 318e3092bfd3ebca70199535e7d90f311622d41b..506d7f4bd787f336eb1fc11fffe65c29b02e44ce 100644 (file)
@@ -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;
index 6bfd57af23ace6715ad8973dd0e54f5ae749ef12..d8ead0ee42a9b93e0c4b1890db695cd1c7b659b1 100644 (file)
@@ -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(); }