Remove unused hex function
This allows us to also remove the cache class which was only used here
This commit is contained in:
parent
b238ec3403
commit
64fa6469ab
@ -1,35 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include "common.hpp"
|
|
||||||
#include "utils/concurrency.hpp"
|
|
||||||
|
|
||||||
POLYBAR_NS
|
|
||||||
|
|
||||||
template <typename ValueType, typename KeyType>
|
|
||||||
class cache {
|
|
||||||
public:
|
|
||||||
using map_type = std::unordered_map<KeyType, std::weak_ptr<ValueType>>;
|
|
||||||
using safe_map_type = mutex_wrapper<map_type>;
|
|
||||||
|
|
||||||
bool check(const KeyType& key) {
|
|
||||||
std::lock_guard<safe_map_type> guard(m_cache);
|
|
||||||
return m_cache.find(key) == m_cache.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... MakeArgs>
|
|
||||||
shared_ptr<ValueType> object(const KeyType& key, MakeArgs&&... make_args) {
|
|
||||||
std::lock_guard<safe_map_type> guard(m_cache);
|
|
||||||
auto ptr = m_cache[key].lock();
|
|
||||||
if (!ptr) {
|
|
||||||
m_cache[key] = ptr = make_shared<ValueType>(forward<MakeArgs>(make_args)...);
|
|
||||||
}
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
safe_map_type m_cache;
|
|
||||||
};
|
|
||||||
|
|
||||||
POLYBAR_NS_END
|
|
@ -3,12 +3,9 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "utils/cache.hpp"
|
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
static cache<string, uint32_t> g_cache_hex;
|
|
||||||
|
|
||||||
struct rgba {
|
struct rgba {
|
||||||
/**
|
/**
|
||||||
* Color value in the form ARGB or A000 depending on the type
|
* 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 green_channel(const uint32_t value);
|
||||||
uint8_t blue_channel(const uint32_t value);
|
uint8_t blue_channel(const uint32_t value);
|
||||||
|
|
||||||
string hex(uint32_t color);
|
|
||||||
|
|
||||||
string simplify_hex(string hex);
|
string simplify_hex(string hex);
|
||||||
} // namespace color_util
|
} // namespace color_util
|
||||||
|
|
||||||
|
@ -147,10 +147,6 @@ uint8_t color_util::blue_channel(const uint32_t value) {
|
|||||||
return value & 0xFF;
|
return value & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
string color_util::hex(uint32_t color) {
|
|
||||||
return *g_cache_hex.object(color, [&] { return static_cast<string>(rgba{color}); }());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rgba::has_color() const {
|
bool rgba::has_color() const {
|
||||||
return m_type != NONE;
|
return m_type != NONE;
|
||||||
}
|
}
|
||||||
|
@ -114,15 +114,6 @@ TEST(ColorUtil, rgba) {
|
|||||||
EXPECT_EQ(0x00FFFFFF, static_cast<uint32_t>(rgba{"#00FFFFFF"}));
|
EXPECT_EQ(0x00FFFFFF, static_cast<uint32_t>(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) {
|
TEST(ColorUtil, simplify) {
|
||||||
EXPECT_EQ("#111", color_util::simplify_hex("#FF111111"));
|
EXPECT_EQ("#111", color_util::simplify_hex("#FF111111"));
|
||||||
EXPECT_EQ("#234", color_util::simplify_hex("#ff223344"));
|
EXPECT_EQ("#234", color_util::simplify_hex("#ff223344"));
|
||||||
|
Loading…
Reference in New Issue
Block a user