From dc2047e7c4cffa265e9b2da6504e5f6533ca5f56 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Mon, 8 Jun 2015 14:50:58 +0200 Subject: [PATCH] Replace Transaction::reset() by ~Transaction(). Replace RefillPool by new Transaction. Simplifies code, removes duplication. --- include/cling/Interpreter/Transaction.h | 4 ---- lib/Interpreter/Transaction.cpp | 21 --------------------- lib/Interpreter/TransactionPool.h | 25 ++++++++----------------- 3 files changed, 8 insertions(+), 42 deletions(-) diff --git a/include/cling/Interpreter/Transaction.h b/include/cling/Interpreter/Transaction.h index 9f1be37a..891d3c68 100644 --- a/include/cling/Interpreter/Transaction.h +++ b/include/cling/Interpreter/Transaction.h @@ -491,10 +491,6 @@ namespace cling { /// void erase(iterator pos); - ///\brief Resets empty transaction so that it could be reused. - /// - void reset(); - ///\brief Prints out all the declarations in the transaction. /// void dump() const; diff --git a/lib/Interpreter/Transaction.cpp b/lib/Interpreter/Transaction.cpp index cb432c41..fd5a3fe9 100644 --- a/lib/Interpreter/Transaction.cpp +++ b/lib/Interpreter/Transaction.cpp @@ -111,27 +111,6 @@ namespace cling { m_NestedTransactions.reset(0); } - void Transaction::reset() { - assert((empty() || getState() == kRolledBack) - && "The transaction must be empty."); - // When we unload we want to clear the containers. - if (!empty()) { - m_DeserializedDeclQueue.clear(); - m_DeclQueue.clear(); - m_MacroDirectiveInfoQueue.clear(); - } - if (Transaction* parent = getParent()) - parent->removeNestedTransaction(this); - m_Parent = 0; - m_State = kCollecting; - m_IssuedDiags = kNone; - m_Opts = CompilationOptions(); - m_NestedTransactions.reset(0); // FIXME: leaks the nested transactions. - m_Module = 0; - m_WrapperFD = 0; - m_Next = 0; - } - void Transaction::append(DelayCallInfo DCI) { assert(!DCI.m_DGR.isNull() && "Appending null DGR?!"); assert(getState() == kCollecting diff --git a/lib/Interpreter/TransactionPool.h b/lib/Interpreter/TransactionPool.h index 5d8064f9..cd375adc 100644 --- a/lib/Interpreter/TransactionPool.h +++ b/lib/Interpreter/TransactionPool.h @@ -42,20 +42,11 @@ namespace cling { #endif private: - void RefillPool() { - // Allocate them in one block, containing 8 transactions. - //Transaction* arrayStart = new Transaction[TRANSACTIONS_IN_BLOCK](); - for (size_t i = 0; i < TRANSACTIONS_IN_BLOCK; ++i) - m_Transactions.push_back(new Transaction(m_Sema)); - //m_TransactionBlocks.push_back(arrayStart); - } - public: TransactionPool(clang::Sema& S) : m_Sema(S) { #ifndef NDEBUG m_Debug = false; #endif - RefillPool(); } ~TransactionPool() { @@ -64,9 +55,9 @@ namespace cling { } Transaction* takeTransaction() { - if (m_Transactions.size() == 0) - RefillPool(); - Transaction* T = m_Transactions.pop_back_val(); + if (m_Transactions.empty()) + return new Transaction(m_Sema); + Transaction* T = new (m_Transactions.pop_back_val()) Transaction(m_Sema); #ifndef NDEBUG // *Very useful for debugging purposes and setting breakpoints in gdb. if (m_Debug) @@ -82,17 +73,17 @@ namespace cling { T->getState() == Transaction::kRolledBack) && "Transaction must completed!"); - if (m_Transactions.size() == POOL_SIZE) { - // Tell the parent that T is gone. - if (T->getParent()) - T->getParent()->removeNestedTransaction(T); + // Tell the parent that T is gone. + if (T->getParent()) + T->getParent()->removeNestedTransaction(T); + if (m_Transactions.size() == POOL_SIZE) { // don't overflow the pool delete T; return; } - T->reset(); T->m_State = Transaction::kNumStates; + T->~Transaction(); m_Transactions.push_back(T); } #undef POOL_SIZE