Replace Transaction::reset() by ~Transaction(). Replace RefillPool by new Transaction.

Simplifies code, removes duplication.
This commit is contained in:
Axel Naumann 2015-06-08 14:50:58 +02:00 committed by sftnight
parent 886f586b08
commit dc2047e7c4
3 changed files with 8 additions and 42 deletions

View File

@ -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;

View File

@ -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

View File

@ -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