input/cache/Manager: use IntrusiveHashSet instead of boost::intrusive::set
This commit is contained in:
parent
7e7cdf73b9
commit
5844242cfb
|
@ -23,8 +23,7 @@
|
||||||
#include "input/BufferingInputStream.hxx"
|
#include "input/BufferingInputStream.hxx"
|
||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
#include "util/IntrusiveList.hxx"
|
#include "util/IntrusiveList.hxx"
|
||||||
|
#include "util/IntrusiveHashSet.hxx"
|
||||||
#include <boost/intrusive/set_hook.hpp>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ class InputCacheLease;
|
||||||
class InputCacheItem final
|
class InputCacheItem final
|
||||||
: public BufferingInputStream,
|
: public BufferingInputStream,
|
||||||
public AutoUnlinkIntrusiveListHook,
|
public AutoUnlinkIntrusiveListHook,
|
||||||
public boost::intrusive::set_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>>
|
public IntrusiveHashSetHook<>
|
||||||
{
|
{
|
||||||
const std::string uri;
|
const std::string uri;
|
||||||
|
|
||||||
|
@ -53,8 +52,8 @@ public:
|
||||||
explicit InputCacheItem(InputStreamPtr _input) noexcept;
|
explicit InputCacheItem(InputStreamPtr _input) noexcept;
|
||||||
~InputCacheItem() noexcept;
|
~InputCacheItem() noexcept;
|
||||||
|
|
||||||
const char *GetUri() const noexcept {
|
const std::string &GetUri() const noexcept {
|
||||||
return uri.c_str();
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
using BufferingInputStream::size;
|
using BufferingInputStream::size;
|
||||||
|
|
|
@ -27,25 +27,37 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
inline bool
|
inline std::size_t
|
||||||
InputCacheManager::ItemCompare::operator()(const InputCacheItem &a,
|
InputCacheManager::ItemHash::operator()(std::string_view uri) const noexcept
|
||||||
const char *b) const noexcept
|
|
||||||
{
|
{
|
||||||
return strcmp(a.GetUri(), b) < 0;
|
return std::hash<std::string_view>{}(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t
|
||||||
|
InputCacheManager::ItemHash::operator()(const InputCacheItem &item) const noexcept
|
||||||
|
{
|
||||||
|
return std::hash<std::string_view>{}(item.GetUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
InputCacheManager::ItemCompare::operator()(const char *a,
|
InputCacheManager::ItemEqual::operator()(const InputCacheItem &a,
|
||||||
const InputCacheItem &b) const noexcept
|
std::string_view b) const noexcept
|
||||||
{
|
{
|
||||||
return strcmp(a, b.GetUri()) < 0;
|
return a.GetUri() == b;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
InputCacheManager::ItemCompare::operator()(const InputCacheItem &a,
|
InputCacheManager::ItemEqual::operator()(std::string_view a,
|
||||||
const InputCacheItem &b) const noexcept
|
const InputCacheItem &b) const noexcept
|
||||||
{
|
{
|
||||||
return strcmp(a.GetUri(), b.GetUri()) < 0;
|
return a == b.GetUri();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
InputCacheManager::ItemEqual::operator()(const InputCacheItem &a,
|
||||||
|
const InputCacheItem &b) const noexcept
|
||||||
|
{
|
||||||
|
return a.GetUri() == b.GetUri();
|
||||||
}
|
}
|
||||||
|
|
||||||
InputCacheManager::InputCacheManager(const InputCacheConfig &config) noexcept
|
InputCacheManager::InputCacheManager(const InputCacheConfig &config) noexcept
|
||||||
|
@ -97,8 +109,7 @@ InputCacheManager::Get(const char *uri, bool create)
|
||||||
if (!PathTraitsUTF8::IsAbsolute(uri))
|
if (!PathTraitsUTF8::IsAbsolute(uri))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto iter = items_by_uri.find(uri, items_by_uri.key_comp());
|
if (auto iter = items_by_uri.find(uri); iter != items_by_uri.end()) {
|
||||||
if (iter != items_by_uri.end()) {
|
|
||||||
auto &item = *iter;
|
auto &item = *iter;
|
||||||
|
|
||||||
/* refresh */
|
/* refresh */
|
||||||
|
|
|
@ -21,10 +21,9 @@
|
||||||
#define MPD_INPUT_CACHE_MANAGER_HXX
|
#define MPD_INPUT_CACHE_MANAGER_HXX
|
||||||
|
|
||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
|
#include "util/IntrusiveHashSet.hxx"
|
||||||
#include "util/IntrusiveList.hxx"
|
#include "util/IntrusiveList.hxx"
|
||||||
|
|
||||||
#include <boost/intrusive/set.hpp>
|
|
||||||
|
|
||||||
class InputStream;
|
class InputStream;
|
||||||
class InputCacheItem;
|
class InputCacheItem;
|
||||||
class InputCacheLease;
|
class InputCacheLease;
|
||||||
|
@ -41,13 +40,21 @@ class InputCacheManager {
|
||||||
|
|
||||||
size_t total_size = 0;
|
size_t total_size = 0;
|
||||||
|
|
||||||
struct ItemCompare {
|
struct ItemHash {
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
bool operator()(const InputCacheItem &a,
|
std::size_t operator()(std::string_view uri) const noexcept;
|
||||||
const char *b) const noexcept;
|
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
bool operator()(const char *a,
|
std::size_t operator()(const InputCacheItem &item) const noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ItemEqual {
|
||||||
|
[[gnu::pure]]
|
||||||
|
bool operator()(const InputCacheItem &a,
|
||||||
|
std::string_view b) const noexcept;
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
bool operator()(std::string_view a,
|
||||||
const InputCacheItem &b) const noexcept;
|
const InputCacheItem &b) const noexcept;
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
|
@ -58,10 +65,7 @@ class InputCacheManager {
|
||||||
IntrusiveList<InputCacheItem> items_by_time;
|
IntrusiveList<InputCacheItem> items_by_time;
|
||||||
|
|
||||||
using UriMap =
|
using UriMap =
|
||||||
boost::intrusive::set<InputCacheItem,
|
IntrusiveHashSet<InputCacheItem, 127, ItemHash, ItemEqual>;
|
||||||
boost::intrusive::base_hook<boost::intrusive::set_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>>>,
|
|
||||||
boost::intrusive::compare<ItemCompare>,
|
|
||||||
boost::intrusive::constant_time_size<false>>;
|
|
||||||
|
|
||||||
UriMap items_by_uri;
|
UriMap items_by_uri;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
CacheInputStream::CacheInputStream(InputCacheLease _lease,
|
CacheInputStream::CacheInputStream(InputCacheLease _lease,
|
||||||
Mutex &_mutex) noexcept
|
Mutex &_mutex) noexcept
|
||||||
:InputStream(_lease->GetUri(), _mutex),
|
:InputStream(_lease->GetUri().c_str(), _mutex),
|
||||||
InputCacheLease(std::move(_lease))
|
InputCacheLease(std::move(_lease))
|
||||||
{
|
{
|
||||||
const auto &i = GetCacheItem();
|
const auto &i = GetCacheItem();
|
||||||
|
|
Loading…
Reference in New Issue