1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[ClosedTabsManager] Use QLinkedList for storing closed tabs

The operations prepend() and takeFirst() are O(1) in linked list
This commit is contained in:
nowrep 2014-02-10 19:23:08 +01:00
parent b88bbe4fc8
commit 51498fdb6e
2 changed files with 30 additions and 22 deletions

View File

@ -42,43 +42,49 @@ void ClosedTabsManager::saveView(WebTab* tab, int position)
m_closedTabs.prepend(closedTab);
}
ClosedTabsManager::Tab ClosedTabsManager::getFirstClosedTab()
bool ClosedTabsManager::isClosedTabAvailable()
{
return !m_closedTabs.isEmpty();
}
ClosedTabsManager::Tab ClosedTabsManager::takeLastClosedTab()
{
Tab tab;
tab.position = -1;
if (m_closedTabs.count() > 0) {
tab = m_closedTabs.first();
m_closedTabs.remove(0);
tab = m_closedTabs.takeFirst();
}
return tab;
}
ClosedTabsManager::Tab ClosedTabsManager::getTabAt(int index)
ClosedTabsManager::Tab ClosedTabsManager::takeTabAt(int index)
{
Tab tab;
tab.position = -1;
if (QzTools::vectorContainsIndex(m_closedTabs, index)) {
tab = m_closedTabs.at(index);
m_closedTabs.remove(index);
QLinkedList<Tab>::iterator it;
int i = 0;
for (it = m_closedTabs.begin(); it != m_closedTabs.end(); ++it, ++i) {
if (i == index) {
tab = *it;
m_closedTabs.erase(it);
break;
}
}
return tab;
}
bool ClosedTabsManager::isClosedTabAvailable()
QLinkedList<ClosedTabsManager::Tab> ClosedTabsManager::allClosedTabs()
{
return (m_closedTabs.count() != 0);
return m_closedTabs;
}
void ClosedTabsManager::clearList()
{
m_closedTabs.clear();
}
QVector<ClosedTabsManager::Tab> ClosedTabsManager::allClosedTabs()
{
return m_closedTabs;
}

View File

@ -19,7 +19,7 @@
#define CLOSEDTABSMANAGER_H
#include <QUrl>
#include <QVector>
#include <QLinkedList>
#include "qz_namespace.h"
@ -44,20 +44,22 @@ public:
explicit ClosedTabsManager();
void saveView(WebTab* tab, int position);
ClosedTabsManager::Tab getFirstClosedTab();
ClosedTabsManager::Tab getTabAt(int index);
bool isClosedTabAvailable();
// Takes tab that was most recently closed
Tab takeLastClosedTab();
// Takes tab at given index
Tab takeTabAt(int index);
QLinkedList<Tab> allClosedTabs();
void clearList();
QVector<ClosedTabsManager::Tab> allClosedTabs();
private:
QVector<ClosedTabsManager::Tab> m_closedTabs;
QLinkedList<Tab> m_closedTabs;
};
// Hint to QVector to use std::realloc on item moving
// Hint to Qt to use std::realloc on item moving
Q_DECLARE_TYPEINFO(ClosedTabsManager::Tab, Q_MOVABLE_TYPE);
#endif // CLOSEDTABSMANAGER_H