From: David Faure Date: Mon, 26 Mar 2007 18:34:52 +0000 (+0000) Subject: Using a QLinkedList mostly for "accessing element at index i" is not the best solutio... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/ad6c01d200e2504de1a383355bd82906fe5c06ed Using a QLinkedList mostly for "accessing element at index i" is not the best solution performance-wise... use a QList instead. svn path=/trunk/KDE/kdebase/apps/; revision=646813 --- diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 775ef9864..ebf8a3f82 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -1348,7 +1348,7 @@ void DolphinMainWindow::setupDockWidgets() void DolphinMainWindow::updateHistory() { int index = 0; - const QLinkedList list = m_activeView->urlHistory(index); + const QList list = m_activeView->urlHistory(index); QAction* backAction = actionCollection()->action("go_back"); if (backAction != 0) { diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 99757bac7..311ca36b4 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -453,7 +453,7 @@ void DolphinView::setUrlEditable(bool editable) m_urlNavigator->editUrl(editable); } -const QLinkedList DolphinView::urlHistory(int& index) const +const QList DolphinView::urlHistory(int& index) const { return m_urlNavigator->history(index); } @@ -771,15 +771,14 @@ void DolphinView::showPreview(const KFileItem* item, const QPixmap& pixmap) void DolphinView::restoreContentsPos() { int index = 0; - const QLinkedList history = urlHistory(index); + const QList history = urlHistory(index); if (!history.isEmpty()) { QAbstractItemView* view = itemView(); // TODO: view->setCurrentItem(history[index].currentFileName()); - QLinkedList::const_iterator it = history.begin(); - it += index; - view->horizontalScrollBar()->setValue((*it).contentsX()); - view->verticalScrollBar()->setValue((*it).contentsY()); + const UrlNavigator::HistoryElem& it = history[index]; + view->horizontalScrollBar()->setValue(it.contentsX()); + view->verticalScrollBar()->setValue(it.contentsY()); } } diff --git a/src/dolphinview.h b/src/dolphinview.h index aee10bcad..0bec4824a 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -217,7 +217,7 @@ public: * @param index Output parameter which indicates the current * index of the location. */ - const QLinkedList urlHistory(int& index) const; + const QList urlHistory(int& index) const; /** Returns true, if at least one item is selected. */ bool hasSelection() const; diff --git a/src/urlnavigator.cpp b/src/urlnavigator.cpp index 00edcfe50..1a49b386b 100644 --- a/src/urlnavigator.cpp +++ b/src/urlnavigator.cpp @@ -142,9 +142,7 @@ UrlNavigator::~UrlNavigator() const KUrl& UrlNavigator::url() const { assert(!m_history.empty()); - QLinkedList::const_iterator it = m_history.begin(); - it += m_historyIndex; - return (*it).url(); + return m_history[m_historyIndex].url(); } KUrl UrlNavigator::url(int index) const @@ -167,7 +165,7 @@ KUrl UrlNavigator::url(int index) const return newurl; } -const QLinkedList& UrlNavigator::history(int& index) const +const QList& UrlNavigator::history(int& index) const { index = m_historyIndex; return m_history; @@ -273,26 +271,22 @@ void UrlNavigator::setUrl(const KUrl& url) // Check whether the previous element of the history has the same Url. // If yes, just go forward instead of inserting a duplicate history // element. - QLinkedList::const_iterator it = m_history.begin(); - it += m_historyIndex - 1; - const KUrl& nextUrl = (*it).url(); - if (transformedUrl == nextUrl) { + HistoryElem& prevHistoryElem = m_history[m_historyIndex - 1]; + if (transformedUrl == prevHistoryElem.url()) { goForward(); // kDebug() << "goin' forward in history" << endl; return; } } - QLinkedList::iterator it = m_history.begin() + m_historyIndex; - const KUrl& currUrl = (*it).url(); - if (currUrl == transformedUrl) { + if (this->url() == transformedUrl) { // don't insert duplicate history elements -// kDebug() << "currUrl == transformedUrl" << endl; +// kDebug() << "current url == transformedUrl" << endl; return; } updateHistoryElem(); - m_history.insert(it, HistoryElem(transformedUrl)); + m_history.insert(m_historyIndex, HistoryElem(transformedUrl)); updateContent(); @@ -302,7 +296,7 @@ void UrlNavigator::setUrl(const KUrl& url) // Prevent an endless growing of the history: remembering // the last 100 Urls should be enough... if (m_historyIndex > 100) { - m_history.erase(m_history.begin()); + m_history.removeFirst(); --m_historyIndex; } @@ -326,9 +320,9 @@ void UrlNavigator::requestActivation() void UrlNavigator::storeContentsPosition(int x, int y) { - QLinkedList::iterator it = m_history.begin() + m_historyIndex; - (*it).setContentsX(x); - (*it).setContentsY(y); + HistoryElem& hist = m_history[m_historyIndex]; + hist.setContentsX(x); + hist.setContentsY(y); } void UrlNavigator::keyReleaseEvent(QKeyEvent* event) @@ -498,8 +492,8 @@ void UrlNavigator::updateHistoryElem() assert(m_historyIndex >= 0); const KFileItem* item = 0; // TODO: m_dolphinView->currentFileItem(); if (item != 0) { - QLinkedList::iterator it = m_history.begin() + m_historyIndex; - (*it).setCurrentFileName(item->name()); + HistoryElem& hist = m_history[m_historyIndex]; + hist.setCurrentFileName(item->name()); } } diff --git a/src/urlnavigator.h b/src/urlnavigator.h index 01be439f7..5e0d7f836 100644 --- a/src/urlnavigator.h +++ b/src/urlnavigator.h @@ -24,6 +24,7 @@ #include #include +#include #include class QHBoxLayout; @@ -58,7 +59,7 @@ class ProtocolCombo; * back and forward within this history. */ -typedef QLinkedList UrlStack; +//typedef QList UrlStack; class UrlNavigator : public QWidget { @@ -111,7 +112,7 @@ public: * @param index Output parameter which indicates the current * index of the location. */ - const QLinkedList& history(int& index) const; + const QList& history(int& index) const; /** * Goes back one step in the URL history. The signals @@ -304,7 +305,7 @@ private: QHBoxLayout* m_layout; - QLinkedList m_history; + QList m_history; QToolButton* m_toggleButton; BookmarkSelector* m_bookmarkSelector; KUrlComboBox* m_pathBox;