[vlc-commits] [Git][videolan/vlc][master] qt: diffutil should only be run on the items within limit

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sun Sep 3 10:58:54 UTC 2023



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
b5f72f80 by Pierre Lamot at 2023-09-03T10:45:29+00:00
qt: diffutil should only be run on the items within limit

fix: #28347

- - - - -


2 changed files:

- modules/gui/qt/medialibrary/mllistcache.cpp
- modules/gui/qt/medialibrary/mllistcache.hpp


Changes:

=====================================
modules/gui/qt/medialibrary/mllistcache.cpp
=====================================
@@ -25,20 +25,20 @@ namespace {
 
 uint32_t cacheDataLength(const void* data)
 {
-    auto list = static_cast<const std::vector<MLListCache::ItemType>*>(data);
-    assert(list);
-    return list->size();
+    auto cache = static_cast<const MLListCache::CacheData*>(data);
+    assert(cache);
+    return std::min(cache->loadedCount, cache->queryCount);
 }
 
 bool cacheDataCompare(const void* dataOld, uint32_t oldIndex, const void* dataNew,  uint32_t newIndex)
 {
-    auto listOld = static_cast<const std::vector<MLListCache::ItemType>*>(dataOld);
-    auto listNew = static_cast<const std::vector<MLListCache::ItemType>*>(dataNew);
-    assert(listOld);
-    assert(listNew);
-    assert(oldIndex < listOld->size());
-    assert(newIndex < listNew->size());
-    return listOld->at(oldIndex)->getId() == listNew->at(newIndex)->getId();
+    auto cacheOld = static_cast<const MLListCache::CacheData*>(dataOld);
+    auto cacheNew = static_cast<const MLListCache::CacheData*>(dataNew);
+    assert(cacheOld);
+    assert(cacheNew);
+    assert(oldIndex < cacheOld->list.size());
+    assert(newIndex < cacheNew->list.size());
+    return cacheNew->list[newIndex]->getId() == cacheOld->list[oldIndex]->getId();
 }
 
 }
@@ -354,13 +354,13 @@ void MLListCache::partialUpdate()
         cacheDataCompare
     };
 
-    diffutil_snake_t* snake = vlc_diffutil_build_snake(&diffOp, &m_oldData->list, &m_cachedData->list);
+    diffutil_snake_t* snake = vlc_diffutil_build_snake(&diffOp, m_oldData.get(), m_cachedData.get());
     int diffutilFlags = VLC_DIFFUTIL_RESULT_AGGREGATE;
     if (m_useMove)
         diffutilFlags |= VLC_DIFFUTIL_RESULT_MOVE;
 
     vlc_diffutil_changelist_t* changes = vlc_diffutil_build_change_list(
-        snake, &diffOp, &m_oldData->list, &m_cachedData->list,
+        snake, &diffOp, m_oldData.get(), m_cachedData.get(),
         diffutilFlags);
 
     m_partialIndex = 0;


=====================================
modules/gui/qt/medialibrary/mllistcache.hpp
=====================================
@@ -120,6 +120,26 @@ class MLListCache : public QObject
 public:
     typedef std::unique_ptr<MLItem> ItemType;
 
+    struct CacheData {
+        explicit CacheData(std::vector<ItemType>&& list_,
+                           size_t queryCount_,
+                           size_t maximumCount_)
+            : list(std::move(list_))
+            , queryCount(queryCount_)
+            , maximumCount(maximumCount_)
+        {
+            loadedCount = list.size();
+        }
+
+        std::vector<ItemType> list;
+        //How many items are does the query returns min(maximumCount - offset, limit)
+        size_t queryCount = 0;
+        //how many items in the table
+        size_t maximumCount = 0;
+        //how many items are loaded (list.size)
+        size_t loadedCount = 0;
+    };
+
 public:
     static constexpr ssize_t COUNT_UNINITIALIZED = -1;
 
@@ -244,26 +264,6 @@ private:
     uint64_t m_appendTask = 0;
     uint64_t m_countTask = 0;
 
-    struct CacheData {
-        explicit CacheData(std::vector<ItemType>&& list_,
-                           size_t queryCount_,
-                           size_t maximumCount_)
-            : list(std::move(list_))
-            , queryCount(queryCount_)
-            , maximumCount(maximumCount_)
-        {
-            loadedCount = list.size();
-        }
-
-        std::vector<ItemType> list;
-        //How many items are does the query returns min(maximumCount - offset, limit)
-        size_t queryCount = 0;
-        //how many items in the table
-        size_t maximumCount = 0;
-        //how many items are loaded (list.size)
-        size_t loadedCount = 0;
-    };
-
     std::unique_ptr<CacheData> m_cachedData;
     std::unique_ptr<CacheData> m_oldData;
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/b5f72f801b8e34a3d71360690d1ce9034db07fd5

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/b5f72f801b8e34a3d71360690d1ce9034db07fd5
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list