tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 1ad1b18a5248e58d3b99163587656b2d16fe58af
parent 8a28ab14664107096b1a47f3d1e33f00822b8d75
Author: serge-sans-paille <sguelton@mozilla.com>
Date:   Thu,  9 Oct 2025 11:47:34 +0000

Bug 1993179 - Simplify mozilla::detail::EmptyChecker implementation r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D267924

Diffstat:
Mmfbt/MruCache.h | 19++++++++-----------
Mxpcom/tests/gtest/TestMruCache.cpp | 30------------------------------
2 files changed, 8 insertions(+), 41 deletions(-)

diff --git a/mfbt/MruCache.h b/mfbt/MruCache.h @@ -22,15 +22,14 @@ namespace detail { // // `IsNotEmpty` will return true if `Value` is not a pointer type or if the // pointer value is not null. -template <typename Value, bool IsPtr = std::is_pointer<Value>::value> -struct EmptyChecker { - static bool IsNotEmpty(const Value&) { return true; } -}; -// Template specialization for the `IsPtr == true` case. template <typename Value> -struct EmptyChecker<Value, true> { - static bool IsNotEmpty(const Value& aVal) { return aVal != nullptr; } -}; +constexpr bool IsNotEmpty(const Value& aVal) { + if constexpr (!std::is_pointer_v<Value>) { + return true; + } else { + return aVal != nullptr; + } +} } // namespace detail @@ -145,10 +144,8 @@ class MruCache { // present, update the entry to a new value, or remove the entry if one was // matched. Entry Lookup(const KeyType& aKey) { - using EmptyChecker = detail::EmptyChecker<ValueType>; - auto entry = RawEntry(aKey); - bool match = EmptyChecker::IsNotEmpty(*entry) && Cache::Match(aKey, *entry); + bool match = detail::IsNotEmpty(*entry) && Cache::Match(aKey, *entry); return Entry(entry, match); } diff --git a/xpcom/tests/gtest/TestMruCache.cpp b/xpcom/tests/gtest/TestMruCache.cpp @@ -55,36 +55,6 @@ static nsCString MakeStringKey(char aKey) { return key; } -TEST(MruCache, TestNullChecker) -{ - using mozilla::detail::EmptyChecker; - - { - int test = 0; - EXPECT_TRUE(EmptyChecker<decltype(test)>::IsNotEmpty(test)); - - test = 42; - EXPECT_TRUE(EmptyChecker<decltype(test)>::IsNotEmpty(test)); - } - - { - const char* test = "abc"; - EXPECT_TRUE(EmptyChecker<decltype(test)>::IsNotEmpty(test)); - - test = nullptr; - EXPECT_FALSE(EmptyChecker<decltype(test)>::IsNotEmpty(test)); - } - - { - int foo = 42; - int* test = &foo; - EXPECT_TRUE(EmptyChecker<decltype(test)>::IsNotEmpty(test)); - - test = nullptr; - EXPECT_FALSE(EmptyChecker<decltype(test)>::IsNotEmpty(test)); - } -} - TEST(MruCache, TestEmptyCache) { {