From f5c688cadc9714b9a5f7b6ec6c8bc084391cf38f Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 30 May 2012 17:55:25 +0200 Subject: [PATCH] debugger: save a few cycles in the watchmodel Change-Id: I56afd567361b2a65db4e0103a64540dc4305981c Reviewed-by: hjk --- src/plugins/debugger/watchhandler.cpp | 38 +++++++++++++++++++-------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 890f68456f1..46717ca2cd5 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -119,20 +119,23 @@ static QByteArray stripForFormat(const QByteArray &ba) // destruction of items. class WatchItem; +typedef QList WatchItems; + WatchItem *itemConstructor(WatchModel *model, const QByteArray &iname); void itemDestructor(WatchModel *model, WatchItem *item); class WatchItem : public WatchData { public: - WatchItem *parent; - QList children; + WatchItem *parent; // Not owned. + WatchItems children; // Not owned. Handled via itemDestructor(). + bool modified; private: friend WatchItem *itemConstructor(WatchModel *model, const QByteArray &iname); friend void itemDestructor(WatchModel *model, WatchItem *item); - WatchItem() { parent = 0; } + WatchItem() { parent = 0; modified = false; } ~WatchItem() {} WatchItem(const WatchItem &); // Not implemented. }; @@ -175,6 +178,8 @@ private: void fetchMore(const QModelIndex &parent); void invalidateAll(const QModelIndex &parentIndex = QModelIndex()); + void unmodifyTree(WatchItem *item); + WatchItem *createItem(const QByteArray &iname, const QString &name, WatchItem *parent); friend class WatchHandler; @@ -192,7 +197,7 @@ private: void reinitialize(); void destroyItem(WatchItem *item); // With model notification. void destroyChildren(WatchItem *item); // With model notification. - void destroyHelper(const QList &items); // Without model notification. + void destroyHelper(const WatchItems &items); // Without model notification. void emitDataChanged(int column, const QModelIndex &parentIndex = QModelIndex()); @@ -347,7 +352,7 @@ void WatchModel::dumpHelper(WatchItem *item) dumpHelper(child); } -void WatchModel::destroyHelper(const QList &items) +void WatchModel::destroyHelper(const WatchItems &items) { for (int i = items.size(); --i >= 0; ) { WatchItem *item = items.at(i); @@ -387,7 +392,7 @@ void WatchModel::destroyChildren(WatchItem *item) if (item->children.isEmpty()) return; - QList items = item->children; + WatchItems items = item->children; // Deregister from model and parent. // It's sufficient to do this non-recursively. @@ -767,16 +772,18 @@ QModelIndex WatchModel::parent(const QModelIndex &idx) const return QModelIndex(); const WatchItem *item = watchItem(idx); - if (!item->parent || item->parent == m_root) + const WatchItem *father = watchItem(idx); + if (!father || father == m_root) return QModelIndex(); - const WatchItem *grandparent = item->parent->parent; + const WatchItem *grandparent = father->parent; if (!grandparent) return QModelIndex(); - for (int i = 0; i < grandparent->children.size(); ++i) - if (grandparent->children.at(i) == item->parent) - return createIndex(i, 0, (void*) item->parent); + const WatchItems &uncles = grandparent->children; + for (int i = 0, n = uncles.size(); i < n; ++i) + if (uncles.at(i) == father) + return createIndex(i, 0, (void*) father); return QModelIndex(); } @@ -851,6 +858,15 @@ void WatchModel::invalidateAll(const QModelIndex &parentIndex) emit dataChanged(idx1, idx2); } +void WatchModel::unmodifyTree(WatchItem *item) +{ + item->modified = false; + const WatchItems &items = item->children; + for (int i = items.size(); --i >= 0; ) + unmodifyTree(items.at(i)); + +} + // Truncate value for item view, maintaining quotes. static QString truncateValue(QString v) {