mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
speed up Unserialize_impl for prevector
The unserializer for prevector uses resize() for reserve the area, but it's prefer to use reserve() because resize() have overhead to call its constructor many times. However, reserve() does not change the value of "_size" (a private member of prevector). This PR introduce resize_uninitialized() to prevector that similar to resize() but does not call constructor, and added elements are explicitly initialized in Unserialize_imple(). The changes are as follows: 1. prevector.h Add a public member function named 'resize_uninitialized'. This function processes like as resize() but does not call constructors. So added elemensts needs explicitly initialized after this returns. 2. serialize.h In the following two function: Unserialize_impl(Stream& is, prevector<N, T>& v, const unsigned char&) Unserialize_impl(Stream& is, prevector<N, T>& v, const V&) Calls resize_uninitialized() instead of resize() 3. test/prevector_tests.cpp Add a test for resize_uninitialized().
This commit is contained in:
@@ -659,7 +659,7 @@ void Unserialize_impl(Stream& is, prevector<N, T>& v, const unsigned char&)
|
||||
while (i < nSize)
|
||||
{
|
||||
unsigned int blk = std::min(nSize - i, (unsigned int)(1 + 4999999 / sizeof(T)));
|
||||
v.resize(i + blk);
|
||||
v.resize_uninitialized(i + blk);
|
||||
is.read((char*)&v[i], blk * sizeof(T));
|
||||
i += blk;
|
||||
}
|
||||
@@ -677,8 +677,8 @@ void Unserialize_impl(Stream& is, prevector<N, T>& v, const V&)
|
||||
nMid += 5000000 / sizeof(T);
|
||||
if (nMid > nSize)
|
||||
nMid = nSize;
|
||||
v.resize(nMid);
|
||||
for (; i < nMid; i++)
|
||||
v.resize_uninitialized(nMid);
|
||||
for (; i < nMid; ++i)
|
||||
Unserialize(is, v[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user