VirtualBox

Changeset 85594 in vbox


Ignore:
Timestamp:
Aug 3, 2020 10:48:32 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9686, bugref:9510. Don't cache QVector's indices. That is very stupid

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.cpp

    r85592 r85594  
    303303    const QMap<int, int> dataLengths() const;
    304304    QUuid itemUid(int iIndex);
     305    int itemIndex(const QUuid &uid);
    305306
    306307private slots:
     
    320321
    321322    QVector<UIResourceMonitorItem> m_itemList;
    322     /* Used to find machines by uid. key is the machine uid and int is the index to m_itemList */
    323     QMap<QUuid, int>               m_itemMap;
    324323    QMap<int, QString> m_columnTitles;
    325324    QTimer *m_pTimer;
     
    956955}
    957956
     957int UIResourceMonitorModel::itemIndex(const QUuid &uid)
     958{
     959    for (int i = 0; i < m_itemList.size(); ++i)
     960    {
     961        if (m_itemList[i].m_VMuid == uid)
     962            return i;
     963    }
     964    return -1;
     965}
     966
    958967QVariant UIResourceMonitorModel::data(const QModelIndex &index, int role) const
    959968{
     
    990999void UIResourceMonitorModel::sltMachineStateChanged(const QUuid &uId, const KMachineState state)
    9911000{
    992     int iIndex = m_itemMap.value(uId, -1);
     1001    int iIndex = itemIndex(uId);
    9931002    /* Remove the machine in case machine is no longer working. */
    9941003    if (iIndex != -1 && state != KMachineState_Running)
     
    11981207                    if (comMachine.isNull())
    11991208                        continue;
    1200                     int iIndex = m_itemMap.value(comMachine.GetId(), -1);
     1209                    int iIndex = itemIndex(comMachine.GetId());
    12011210                    if (iIndex == -1 || iIndex >= m_itemList.size())
    12021211                        continue;
     
    12531262void UIResourceMonitorModel::addItem(const QUuid& uMachineId, const QString& strMachineName)
    12541263{
    1255     int iIndex = m_itemList.size();
    12561264    m_itemList.append(UIResourceMonitorItem(uMachineId, strMachineName));
    1257     m_itemMap[uMachineId] = iIndex;
    12581265}
    12591266
    12601267void UIResourceMonitorModel::removeItem(const QUuid& uMachineId)
    12611268{
    1262     int iIndex = m_itemMap.value(uMachineId, -1);
     1269    int iIndex = itemIndex(uMachineId);
    12631270    if (iIndex == -1)
    12641271        return;
    12651272    m_itemList.remove(iIndex);
    1266     m_itemMap.remove(uMachineId);
    12671273}
    12681274
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette