db_lmdb: minor pedantic tweaks

Add consts in a few places where it makes sense, avoid unnecessary
memory reallocation where we know the full size needed at the outset,
simplify and avoid memory copy.
This commit is contained in:
moneromooo-monero 2016-12-01 14:28:09 +00:00
parent 3465c4ebc7
commit bef51e677e
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
1 changed files with 8 additions and 8 deletions

View File

@ -880,12 +880,11 @@ void BlockchainLMDB::remove_tx_outputs(const uint64_t tx_id, const transaction&
throw0(DB_ERROR("tx has outputs, but no output indices found"));
}
bool is_miner_tx = tx.vin.size() == 1 && tx.vin[0].type() == typeid(txin_gen);
for (uint64_t i = tx.vout.size(); i > 0; --i)
bool is_pseudo_rct = tx.version >= 2 && tx.vin.size() == 1 && tx.vin[0].type() == typeid(txin_gen);
for (size_t i = tx.vout.size(); i-- > 0;)
{
const tx_out tx_output = tx.vout[i-1];
uint64_t amount = is_miner_tx && tx.version >= 2 ? 0 : tx_output.amount;
remove_output(amount, amount_output_indices[i-1]);
uint64_t amount = is_pseudo_rct ? 0 : tx.vout[i].amount;
remove_output(amount, amount_output_indices[i]);
}
}
@ -906,7 +905,7 @@ void BlockchainLMDB::remove_output(const uint64_t amount, const uint64_t& out_in
else if (result)
throw0(DB_ERROR(lmdb_error("DB error attempting to get an output", result).c_str()));
outkey *ok = (outkey *)v.mv_data;
const pre_rct_outkey *ok = (const pre_rct_outkey *)v.mv_data;
MDB_val_set(otxk, ok->output_id);
result = mdb_cursor_get(m_cur_output_txs, (MDB_val *)&zerokval, &otxk, MDB_GET_BOTH);
if (result == MDB_NOTFOUND)
@ -2044,9 +2043,10 @@ std::vector<uint64_t> BlockchainLMDB::get_tx_amount_output_indices(const uint64_
else if (result)
throw0(DB_ERROR(lmdb_error("DB error attempting to get data for tx_outputs[tx_index]", result).c_str()));
uint64_t* indices = (uint64_t*)v.mv_data;
const uint64_t* indices = (const uint64_t*)v.mv_data;
int num_outputs = v.mv_size / sizeof(uint64_t);
amount_output_indices.reserve(num_outputs);
for (int i = 0; i < num_outputs; ++i)
{
// LOG_PRINT_L0("amount output index[" << 2*i << "]" << ": " << paired_indices[2*i] << " global output index: " << paired_indices[2*i+1]);
@ -2647,7 +2647,7 @@ void BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const std::
else if (get_result)
throw0(DB_ERROR(lmdb_error("Error attempting to retrieve an output from the db", get_result).c_str()));
outkey *okp = (outkey *)v.mv_data;
const outkey *okp = (const outkey *)v.mv_data;
tx_indices.push_back(okp->output_id);
}