Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 05dcf6c

Browse files
committed
Schedule performance improvement
1 parent 3ce3375 commit 05dcf6c

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

src/ramobjectmodels/ramabstractdatamodel.cpp

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,18 @@ RamObject *RamAbstractDataModel::get(const QModelIndex &index)
1212
return reinterpret_cast<RamObject*>( iptr );
1313
}
1414

15-
QSet<RamObject *> RamAbstractDataModel::multiLookUp(const QStringList &lookUpKeys, const QStringList &lookUpValues) const
15+
QSet<RamObject *> &RamAbstractDataModel::intersectLookUp(QString lookUpKey, QString lookUpValue, QSet<RamObject *> &objList) const
1616
{
17-
Q_ASSERT(!lookUpKeys.isEmpty());
18-
Q_ASSERT(lookUpKeys.count() == lookUpValues.count());
19-
20-
QSet<RamObject *> objs = lookUp(
21-
lookUpKeys.first(),
22-
lookUpValues.first()
23-
);
24-
25-
if (lookUpKeys.count() <= 1)
26-
return objs;
27-
28-
for (int i = 1; i < lookUpKeys.count(); ++i) {
29-
objs.intersect(
30-
lookUp(
31-
lookUpKeys.at(i),
32-
lookUpValues.at(i)
33-
)
34-
);
17+
// Don't use another lookup and QSet::intersect,
18+
// as it would be slower
19+
// but actually iterate throught the existing set
20+
QMutableSetIterator<RamObject*> i(objList);
21+
while(i.hasNext()) {
22+
i.next();
23+
RamObject *obj = i.value();
24+
if (obj->getData(lookUpKey).toString() != lookUpValue)
25+
objList.remove(obj);
3526
}
3627

37-
return objs;
38-
}
39-
40-
QSet<RamObject *> RamAbstractDataModel::intersectLookUp(QString lookUpKey, QString lookUpValue, QSet<RamObject *> objList) const
41-
{
42-
return objList.intersect( lookUp(lookUpKey, lookUpValue) );
28+
return objList;
4329
}

src/ramobjectmodels/ramabstractdatamodel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class RamAbstractDataModel
2424
virtual RamObject *search(QString searchString) const = 0;
2525
// Objects by their lookup key
2626
virtual QSet<RamObject *> lookUp(QString lookUpKey, QString lookUpValue) const = 0;
27-
virtual QSet<RamObject *> multiLookUp(const QStringList &lookUpKeys, const QStringList &lookUpValues) const;
28-
virtual QSet<RamObject *> intersectLookUp(QString lookUpKey, QString lookUpValue, QSet<RamObject *> objList) const;
27+
// Modifies the list and returns a reference to it
28+
virtual QSet<RamObject *> &intersectLookUp(QString lookUpKey, QString lookUpValue, QSet<RamObject *> &objList) const;
2929

3030
// All the uuids
3131
virtual QVector<QString> toVector() const = 0;

src/ramobjectmodels/ramscheduletablemodel.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ QVariant RamScheduleTableModel::data(const QModelIndex &index, int role) const
8484
return date;
8585

8686
// Get the entrie(s)
87-
const QSet<RamObject*> entriesSet = m_entries->multiLookUp(
88-
QStringList( { "date", "row" } ),
89-
QStringList( { date.toString( DATE_DATA_FORMAT ), m_rows->getUuid(row) } )
90-
);
87+
QSet<RamObject*> entriesSet = m_entries->lookUp("date", date.toString( DATE_DATA_FORMAT ));
88+
m_entries->intersectLookUp("row", m_rows->getUuid(row), entriesSet);
9189

9290
// Empty cell
9391
if (entriesSet.isEmpty())
@@ -97,24 +95,33 @@ QVariant RamScheduleTableModel::data(const QModelIndex &index, int role) const
9795
if (role == RamAbstractObject::Type)
9896
return RamObject::ScheduleEntry;
9997

100-
// Sort the entries by step order, then title
98+
// Make sure the steps are always returned in the same order
10199
QList<RamObject*> entries = entriesSet.values();
102100
std::sort( entries.begin(), entries.end(), [] (RamObject *a, RamObject *b) {
103101
auto entryA = RamScheduleEntry::c(a);
104102
auto entryB = RamScheduleEntry::c(b);
103+
104+
// Don't actually get the RamStep
105+
// To improve performance just use the uuid
106+
return entryA->getData("step").toString() < entryB->getData("step").toString();
107+
108+
// ======= Disabled better sorting
105109
auto stepA = entryA->step();
106110
auto stepB = entryB->step();
107111

108112
if (stepA && stepB)
109113
return stepA->order() < stepB->order();
114+
110115
if (!stepA && stepB)
111116
return false;
112117
if (stepA && !stepB)
113118
return true;
114119

115120
return entryA->shortName() < entryB->shortName();
121+
// ==========
116122
});
117123

124+
118125
// Pointer list for Multiple entries,
119126
// The delegate should get the list of pointers
120127
// to do something with it...
@@ -140,7 +147,10 @@ QVariant RamScheduleTableModel::data(const QModelIndex &index, int role) const
140147
return entries.first()->roleData(role);
141148
}
142149

150+
151+
//*/
143152
return QVariant();
153+
144154
}
145155

146156
bool RamScheduleTableModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)

0 commit comments

Comments
 (0)