[vlc-devel] [PATCH 6/8] qt: medialib: do not depend on ListCache header

Romain Vimont rom1v at videolabs.io
Thu Dec 3 12:12:10 CET 2020


MLSlidingWindowModel has many subclasses. Since it depended on the
ListCache<T> header, every change in this header caused huge incremental
compilation times.

Before this commit and the two previous ones, here is the time it took
on my machine to recompile after touching listcache.hpp:

    $ time make -j8
    ...
    real    0m45.001s
    user    4m55.672s
    sys     0m9.414s

After these changes:

    $ time make -j8
    real    0m10.676s
    user    0m11.840s
    sys     0m0.946s
---
 modules/gui/qt/Makefile.am                  |  1 +
 modules/gui/qt/medialibrary/mlbasemodel.cpp |  4 +++
 modules/gui/qt/medialibrary/mlbasemodel.hpp | 10 ++++---
 modules/gui/qt/util/listcache.hpp           |  9 +------
 modules/gui/qt/util/listcacheloader.hpp     | 30 +++++++++++++++++++++
 5 files changed, 43 insertions(+), 11 deletions(-)
 create mode 100644 modules/gui/qt/util/listcacheloader.hpp

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 35c8e6223d..26c9966cd0 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -204,6 +204,7 @@ libqt_plugin_la_SOURCES = \
 	gui/qt/util/imagehelper.cpp gui/qt/util/imagehelper.hpp \
 	gui/qt/util/i18n.cpp gui/qt/util/i18n.hpp \
 	gui/qt/util/listcache.hpp \
+	gui/qt/util/listcacheloader.hpp \
 	gui/qt/util/navigation_history.cpp gui/qt/util/navigation_history.hpp \
 	gui/qt/util/qml_main_context.cpp \
 	gui/qt/util/qml_main_context.hpp \
diff --git a/modules/gui/qt/medialibrary/mlbasemodel.cpp b/modules/gui/qt/medialibrary/mlbasemodel.cpp
index c5a00ffe12..4a8f77dca5 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.cpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.cpp
@@ -20,6 +20,7 @@
 #include "mlbasemodel.hpp"
 #include "medialib.hpp"
 #include <vlc_cxx_helpers.hpp>
+#include "util/listcache.hpp"
 
 MLBaseModel::MLBaseModel(QObject *parent)
     : QAbstractListModel(parent)
@@ -214,6 +215,9 @@ MLSlidingWindowModel::MLSlidingWindowModel(QObject *parent)
 {
 }
 
+/* For std::unique_ptr, see Effective Modern C++, Item 22 */
+MLSlidingWindowModel::~MLSlidingWindowModel() = default;
+
 int MLSlidingWindowModel::rowCount(const QModelIndex &parent) const
 {
     if (parent.isValid())
diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp b/modules/gui/qt/medialibrary/mlbasemodel.hpp
index 0daa1cbfa2..da8ec363c7 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.hpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp
@@ -33,7 +33,10 @@
 #include <memory>
 #include "mlevent.hpp"
 #include "mlqueryparams.hpp"
-#include "util/listcache.hpp"
+#include "util/listcacheloader.hpp"
+
+template <typename T>
+class ListCache;
 
 class MediaLib;
 
@@ -134,10 +137,11 @@ protected:
 class MLSlidingWindowModel : public MLBaseModel
 {
 public:
-    static constexpr ssize_t COUNT_UNINITIALIZED =
-        ListCache<std::unique_ptr<MLItem>>::COUNT_UNINITIALIZED;
+    /* ListCache<std::unique_ptr<MLItem>>::COUNT_UNINITIALIZED */
+    static constexpr ssize_t COUNT_UNINITIALIZED = -1;
 
     MLSlidingWindowModel(QObject* parent = nullptr);
+    ~MLSlidingWindowModel();
 
     int rowCount(const QModelIndex &parent = {}) const override;
 
diff --git a/modules/gui/qt/util/listcache.hpp b/modules/gui/qt/util/listcache.hpp
index 141ed7f6b9..e92b7d84df 100644
--- a/modules/gui/qt/util/listcache.hpp
+++ b/modules/gui/qt/util/listcache.hpp
@@ -31,6 +31,7 @@
 #include <QObject>
 #include <QSharedPointer>
 #include "asynctask.hpp"
+#include "listcacheloader.hpp"
 
 /**
  * `ListCache<T>` represents a cache for a (constant) list of items.
@@ -58,14 +59,6 @@
  * All its public methods must be called from the UI thread.
  */
 
-template <typename T>
-struct ListCacheLoader
-{
-    virtual ~ListCacheLoader() = default;
-    virtual size_t count() const = 0;
-    virtual std::vector<T> load(size_t index, size_t count) const = 0;
-};
-
 /* Non-template class for signals */
 class BaseListCache : public QObject
 {
diff --git a/modules/gui/qt/util/listcacheloader.hpp b/modules/gui/qt/util/listcacheloader.hpp
new file mode 100644
index 0000000000..985b464a3c
--- /dev/null
+++ b/modules/gui/qt/util/listcacheloader.hpp
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef LISTCACHELOADER_HPP
+#define LISTCACHELOADER_HPP
+
+template <typename T>
+struct ListCacheLoader
+{
+    virtual ~ListCacheLoader() = default;
+    virtual size_t count() const = 0;
+    virtual std::vector<T> load(size_t index, size_t count) const = 0;
+};
+
+#endif
-- 
2.29.2



More information about the vlc-devel mailing list