[vlc-commits] qt: medialib: do not depend on ListCache header

Romain Vimont git at videolan.org
Tue Dec 8 14:19:22 UTC 2020


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Wed Nov 25 15:47:12 2020 +0100| [a408b11197cab409c8792b3acb12e11b0faed421] | committer: Pierre Lamot

qt: medialib: do not depend on ListCache header

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

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a408b11197cab409c8792b3acb12e11b0faed421
---

 modules/gui/qt/Makefile.am                  |  1 +
 modules/gui/qt/medialibrary/mlbasemodel.cpp |  4 ++++
 modules/gui/qt/medialibrary/mlbasemodel.hpp |  6 +++++-
 modules/gui/qt/util/listcache.hpp           |  9 +--------
 modules/gui/qt/util/listcacheloader.hpp     | 30 +++++++++++++++++++++++++++++
 5 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 83a8eb8b45..f3ea3f2486 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 9cc0df7391..381c18afff 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"
 
 static constexpr ssize_t COUNT_UNINITIALIZED =
     ListCache<std::unique_ptr<MLItem>>::COUNT_UNINITIALIZED;
@@ -217,6 +218,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 eac3f3a811..1a8f07032b 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;
 
@@ -135,6 +138,7 @@ class MLSlidingWindowModel : public MLBaseModel
 {
 public:
     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



More information about the vlc-commits mailing list