[sanitizer] Construct InternalMmapVector without memory allocation.

Construction of InternalMmapVector is often followed by a call to
reserve(), which may result in immediate reallocation of the memory
for the internal storage. This patch delays that allocation until
it is really needed.

Differential Revision: https://reviews.llvm.org/D71342
This commit is contained in:
Igor Kudrin 2019-12-11 17:37:24 +07:00
parent 5279f96577
commit a57adc7a0b
2 changed files with 2 additions and 2 deletions

View File

@ -552,7 +552,7 @@ bool operator!=(const InternalMmapVectorNoCtor<T> &lhs,
template<typename T>
class InternalMmapVector : public InternalMmapVectorNoCtor<T> {
public:
InternalMmapVector() { InternalMmapVectorNoCtor<T>::Initialize(1); }
InternalMmapVector() { InternalMmapVectorNoCtor<T>::Initialize(0); }
explicit InternalMmapVector(uptr cnt) {
InternalMmapVectorNoCtor<T>::Initialize(cnt);
this->resize(cnt);

View File

@ -131,7 +131,7 @@ TEST(SanitizerCommon, InternalMmapVector) {
EXPECT_EQ((uptr)i, vector.size());
}
InternalMmapVector<uptr> empty_vector;
CHECK_GT(empty_vector.capacity(), 0U);
CHECK_EQ(empty_vector.capacity(), 0U);
CHECK_EQ(0U, empty_vector.size());
}