From 64fa6469ab9df2c9ad0e7d57f391409d018fdae3 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Sun, 27 Oct 2019 22:26:02 +0100 Subject: [PATCH] Remove unused hex function This allows us to also remove the cache class which was only used here --- include/utils/cache.hpp | 35 -------------------------------- include/utils/color.hpp | 5 ----- src/utils/color.cpp | 4 ---- tests/unit_tests/utils/color.cpp | 9 -------- 4 files changed, 53 deletions(-) delete mode 100644 include/utils/cache.hpp diff --git a/include/utils/cache.hpp b/include/utils/cache.hpp deleted file mode 100644 index b878a5a2..00000000 --- a/include/utils/cache.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include - -#include "common.hpp" -#include "utils/concurrency.hpp" - -POLYBAR_NS - -template -class cache { - public: - using map_type = std::unordered_map>; - using safe_map_type = mutex_wrapper; - - bool check(const KeyType& key) { - std::lock_guard guard(m_cache); - return m_cache.find(key) == m_cache.end(); - } - - template - shared_ptr object(const KeyType& key, MakeArgs&&... make_args) { - std::lock_guard guard(m_cache); - auto ptr = m_cache[key].lock(); - if (!ptr) { - m_cache[key] = ptr = make_shared(forward(make_args)...); - } - return ptr; - } - - private: - safe_map_type m_cache; -}; - -POLYBAR_NS_END diff --git a/include/utils/color.hpp b/include/utils/color.hpp index bfd60617..f1951f20 100644 --- a/include/utils/color.hpp +++ b/include/utils/color.hpp @@ -3,12 +3,9 @@ #include #include "common.hpp" -#include "utils/cache.hpp" POLYBAR_NS -static cache g_cache_hex; - struct rgba { /** * Color value in the form ARGB or A000 depending on the type @@ -45,8 +42,6 @@ namespace color_util { uint8_t green_channel(const uint32_t value); uint8_t blue_channel(const uint32_t value); - string hex(uint32_t color); - string simplify_hex(string hex); } // namespace color_util diff --git a/src/utils/color.cpp b/src/utils/color.cpp index 6a638880..277a3fd7 100644 --- a/src/utils/color.cpp +++ b/src/utils/color.cpp @@ -147,10 +147,6 @@ uint8_t color_util::blue_channel(const uint32_t value) { return value & 0xFF; } -string color_util::hex(uint32_t color) { - return *g_cache_hex.object(color, [&] { return static_cast(rgba{color}); }()); -} - bool rgba::has_color() const { return m_type != NONE; } diff --git a/tests/unit_tests/utils/color.cpp b/tests/unit_tests/utils/color.cpp index 88454628..5ae9a823 100644 --- a/tests/unit_tests/utils/color.cpp +++ b/tests/unit_tests/utils/color.cpp @@ -114,15 +114,6 @@ TEST(ColorUtil, rgba) { EXPECT_EQ(0x00FFFFFF, static_cast(rgba{"#00FFFFFF"})); } -TEST(ColorUtil, hex) { - uint32_t colorA{0x123456}; - EXPECT_EQ("#00123456"s, color_util::hex(colorA)); - uint32_t colorB{0xCC123456}; - EXPECT_EQ("#cc123456"s, color_util::hex(colorB)); - uint32_t colorC{0x00ffffff}; - EXPECT_EQ("#00ffffff"s, color_util::hex(colorC)); -} - TEST(ColorUtil, simplify) { EXPECT_EQ("#111", color_util::simplify_hex("#FF111111")); EXPECT_EQ("#234", color_util::simplify_hex("#ff223344"));