From: sameer-here <76567789+sameer-here@users.noreply.github.com> Date: Wed, 7 Dec 2022 17:27:47 +0000 (+0000) Subject: Optimize RefCount comparison with raw pointers (#1200) X-Git-Tag: SQUID_6_0_1~64 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=56b2587856ccd0198e488d1f74633c29e20fabd7;p=thirdparty%2Fsquid.git Optimize RefCount comparison with raw pointers (#1200) GCC v12 and Clang v12 tests show that compilers cannot avoid creating temporaries when comparing RefCount objects with arbitrary pointers. Also fixes (not yet supported) C++20 build. C++20 automatically reverses equality comparisons, triggering an ambiguity: src/esi/Esi.cc:1920:26: error: ambiguous overload for 'operator==' (operand types are 'ESISegment::Pointer' {aka 'RefCount'} and std::nullptr_t) assert (output->next == nullptr); src/esi/Esi.cc:77:6: note: candidate: 'bool operator==(const ESIElement*, const Pointer&)' (reversed) src/base/RefCount.h:82:10: note: candidate: 'bool RefCount::operator==(const RefCount&) const [with C = ESISegment]' --- diff --git a/src/base/RefCount.h b/src/base/RefCount.h index 119b74c30b..a9aba7e9ea 100644 --- a/src/base/RefCount.h +++ b/src/base/RefCount.h @@ -87,6 +87,18 @@ public: return p.p_ != p_; } + template + bool operator ==(const Other * const p) const + { + return p == p_; + } + + template + bool operator !=(const Other * const p) const + { + return p != p_; + } + private: void dereference(C const *newP = nullptr) { /* Setting p_ first is important: