Commit 80b1d991 authored by Benjamin Arnaud's avatar Benjamin Arnaud Committed by Hugo Beauzée-Luyssen
Browse files

qt/mlbasemodel: Add the 'itemCache' function

This is useful when we only want to return a cached item.
parent 12d1b4f8
......@@ -408,19 +408,37 @@ void MLBaseModel::invalidateCache()
m_cache.reset();
}
//-------------------------------------------------------------------------------------------------
MLItem *MLBaseModel::item(int signedidx) const
{
validateCache();
ssize_t count = m_cache->count();
if (count == COUNT_UNINITIALIZED || signedidx < 0
|| signedidx >= count)
if (count == COUNT_UNINITIALIZED || signedidx < 0 || signedidx >= count)
return nullptr;
unsigned int idx = static_cast<unsigned int>(signedidx);
m_cache->refer(idx);
const std::unique_ptr<MLItem> *item = m_cache->get(idx);
if (!item)
/* Not in cache */
return nullptr;
/* Return raw pointer */
return item->get();
}
MLItem *MLBaseModel::itemCache(int signedidx) const
{
unsigned int idx = static_cast<unsigned int>(signedidx);
const std::unique_ptr<MLItem> *item = m_cache->get(idx);
if (!item)
/* Not in cache */
return nullptr;
......@@ -429,6 +447,8 @@ MLItem *MLBaseModel::item(int signedidx) const
return item->get();
}
//-------------------------------------------------------------------------------------------------
MLBaseModel::BaseLoader::BaseLoader(vlc_medialibrary_t *ml, MLItemId parent, QString searchPattern,
vlc_ml_sorting_criteria_t sort, bool sort_desc)
: m_ml(ml)
......
......@@ -107,7 +107,12 @@ protected:
void validateCache() const;
void invalidateCache();
MLItem* item(int signedidx) const;
MLItem *item(int signedidx) const;
// NOTE: This is faster because it only returns items available in cache.
MLItem *itemCache(int signedidx) const;
virtual void onVlcMlEvent( const MLEvent &event );
virtual ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment