changeset 23724:caec032574ca

Simple loop optimisation.
author Simon <simon@bitcartel.com>
date Thu, 03 Mar 2016 12:56:54 -0800
parents bac3c81409ed
children b955dedffc7c
files src/thinblock.cpp
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/thinblock.cpp	Thu Feb 25 14:44:27 2016 -0500
+++ b/src/thinblock.cpp	Thu Mar 03 12:56:54 2016 -0800
@@ -8,8 +8,9 @@
 {
     header = block.GetBlockHeader();
 
-    vTxHashes.reserve(block.vtx.size());
-    for (unsigned int i = 0; i < block.vtx.size(); i++)
+	unsigned int num_tx = block.vtx.size();
+    vTxHashes.reserve(num_tx);
+    for (unsigned int i = 0; i < num_tx; i++)
     {
         const uint256& hash = block.vtx[i].GetHash();
         vTxHashes.push_back(hash);
@@ -28,9 +29,10 @@
     header = block.GetBlockHeader();
     this->collision = false;
 
-    vTxHashes.reserve(block.vtx.size());
+	unsigned int num_tx = block.vtx.size();
+    vTxHashes.reserve(num_tx);
     std::set<uint64_t> setPartialTxHash;
-    for (unsigned int i = 0; i < block.vtx.size(); i++)
+    for (unsigned int i = 0; i < num_tx; i++)
     {
         const uint256 hash256 = block.vtx[i].GetHash();
         uint64_t cheapHash = hash256.GetCheapHash();
@@ -54,10 +56,11 @@
     header = block.GetBlockHeader();
     this->collision = false;
 
-    vTxHashes.reserve(block.vtx.size());
+	unsigned int num_tx = block.vtx.size();
+    vTxHashes.reserve(num_tx);
     std::set<uint64_t> setPartialTxHash;
 
-    for (unsigned int i = 1; i < block.vtx.size(); i++)
+    for (unsigned int i = 1; i < num_tx; i++)
     {
         const uint256 hash256 = block.vtx[i].GetHash();
         uint64_t cheapHash = hash256.GetCheapHash();
@@ -80,6 +83,7 @@
     blockhash = blockHash;
 
     CTransaction tx;
-    for (unsigned int i = 0; i < vHashesToRequest.size(); i++)
+    unsigned int n = vHashesToRequest.size();
+    for (unsigned int i = 0; i < n; i++)
         mapTx[vHashesToRequest[i]] = tx;
 }