From 07c8cece056f5b628cfedcaad3cafe930abbcd29 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 5 Mar 2024 16:52:36 -0800 Subject: [PATCH] QHash: merge the two equal_range() overloads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They were literally identical (as in, they used exactly the same letters in the exact same order), but changed on whether *this was const or not. So pass *this as a parameter so we can have just one implementation. QMultiHash doesn't need this change because its non-const equal_range() calls the const version after making a copy. Change-Id: I6818d78a57394e37857bfffd17ba06aee2e7db0b Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qhash.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index cdb4c119cf..781ea1a157 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -1224,22 +1224,23 @@ public: std::pair equal_range(const Key &key) { - auto first = find(key); - auto second = first; - if (second != iterator()) - ++second; - return {first, second}; + return equal_range_impl(*this, key); } - std::pair equal_range(const Key &key) const noexcept { - auto first = find(key); + return equal_range_impl(*this, key); + } +private: + template static auto equal_range_impl(Hash &self, const K &key) + { + auto first = self.find(key); auto second = first; - if (second != iterator()) + if (second != decltype(first){}) ++second; - return {first, second}; + return std::make_pair(first, second); } +public: typedef iterator Iterator; typedef const_iterator ConstIterator; inline qsizetype count() const noexcept { return d ? qsizetype(d->size) : 0; }