perf: reduce queue and autoplay memory footprint
Some checks failed
Build for Windows / build-windows (push) Has been cancelled

This commit is contained in:
joren
2026-03-30 23:24:30 +02:00
parent cfd91f96b5
commit 07d6c8a88d
3 changed files with 36 additions and 28 deletions

View File

@@ -10,9 +10,8 @@
static constexpr int UpcomingIndexRole = Qt::UserRole + 1;
static constexpr int IsPlayNextRole = Qt::UserRole + 2;
static constexpr int TrackJsonRole = Qt::UserRole + 3;
static constexpr int ArtistRole = Qt::UserRole + 4;
static constexpr int DurationRole = Qt::UserRole + 5;
static constexpr int ArtistRole = Qt::UserRole + 3;
static constexpr int DurationRole = Qt::UserRole + 4;
// ---- Custom delegate -------------------------------------------------------
@@ -184,7 +183,6 @@ void QueuePanel::refresh()
auto *item = new QListWidgetItem(title, m_list);
item->setData(UpcomingIndexRole, i);
item->setData(IsPlayNextRole, i < playNextCount);
item->setData(TrackJsonRole, QVariant::fromValue(t));
item->setData(ArtistRole, artist);
item->setData(DurationRole, duration);
}
@@ -205,10 +203,14 @@ void QueuePanel::onRowsMoved()
{
if (m_refreshing) return;
const QVector<QJsonObject> currentUpcoming = m_queue->upcomingTracks();
QVector<QJsonObject> newOrder;
newOrder.reserve(m_list->count());
for (int i = 0; i < m_list->count(); ++i)
newOrder.append(m_list->item(i)->data(TrackJsonRole).value<QJsonObject>());
for (int i = 0; i < m_list->count(); ++i) {
const int prevIndex = m_list->item(i)->data(UpcomingIndexRole).toInt();
if (prevIndex >= 0 && prevIndex < currentUpcoming.size())
newOrder.append(currentUpcoming.at(prevIndex));
}
m_refreshing = true;
m_queue->setUpcomingOrder(newOrder);