From 65052bfc37692b9c766d9be69686503ef154f985 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 24 Nov 2006 22:46:56 +0100 Subject: [PATCH] Code cleanup: Use updateExpr() in insertExpr(). insertExpr() was the only ExprWnd member that inserted the passed-in tree. Now all members allocate copies, and the invokers can delete their trees. --- kdbg/debugger.cpp | 9 ++++++--- kdbg/exprwnd.cpp | 13 +++++++------ kdbg/exprwnd.h | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/kdbg/debugger.cpp b/kdbg/debugger.cpp index 82ca6cd..39596ee 100644 --- a/kdbg/debugger.cpp +++ b/kdbg/debugger.cpp @@ -1336,9 +1336,12 @@ void KDebugger::handleLocals(const char* output) } } // insert all remaining new variables - for (VarTree* v = newVars.first(); v != 0; v = newVars.next()) { + while (!newVars.isEmpty()) + { + VarTree* v = newVars.take(0); TRACE("new var: " + v->getText()); m_localVariables.insertExpr(v); + delete v; repaintNeeded = true; } @@ -1843,8 +1846,8 @@ void KDebugger::addWatch(const QString& t) QString expr = t.stripWhiteSpace(); if (expr.isEmpty()) return; - VarTree* exprItem = new VarTree(expr, VarTree::NKplain); - m_watchVariables.insertExpr(exprItem); + VarTree e(expr, VarTree::NKplain); + VarTree* exprItem = m_watchVariables.insertExpr(&e); // if we are boring ourselves, send down the command if (m_programActive) { diff --git a/kdbg/exprwnd.cpp b/kdbg/exprwnd.cpp index 5a7a2d6..ec5054b 100644 --- a/kdbg/exprwnd.cpp +++ b/kdbg/exprwnd.cpp @@ -286,14 +286,15 @@ void ExprWnd::exprList(QStrList& exprs) } } -void ExprWnd::insertExpr(VarTree* expr) +VarTree* ExprWnd::insertExpr(VarTree* expr) { - // append the expression - insertItem(expr); + // append a new dummy expression + VarTree* display = new VarTree(expr->getText(), VarTree::NKplain); + insertItem(display); - collectUnknownTypes(expr); - - updateValuesWidth(); + // replace it right away + updateExpr(display, expr); + return display; } void ExprWnd::updateExpr(VarTree* expr) diff --git a/kdbg/exprwnd.h b/kdbg/exprwnd.h index 0e4f585..2e92b06 100644 --- a/kdbg/exprwnd.h +++ b/kdbg/exprwnd.h @@ -86,8 +86,9 @@ public: /** fills the list with the expressions at the topmost level */ void exprList(QStrList& exprs); - /** appends var the the end of the tree at the topmost level */ - void insertExpr(VarTree* expr); + /** appends a copy of expr to the end of the tree at the topmost level; + * returns a pointer to the inserted top-level item */ + VarTree* insertExpr(VarTree* expr); /** updates an existing expression */ void updateExpr(VarTree* expr); void updateExpr(VarTree* display, VarTree* newValues); -- 2.11.4.GIT