[sanitizer] Construct InternalMmapVector without memory allocation.
authorIgor Kudrin <ikudrin@accesssoftek.com>
Wed, 11 Dec 2019 10:37:24 +0000 (17:37 +0700)
committerIgor Kudrin <ikudrin@accesssoftek.com>
Tue, 17 Dec 2019 08:03:23 +0000 (15:03 +0700)
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

compiler-rt/lib/sanitizer_common/sanitizer_common.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp

index 87b8f02..3b52172 100644 (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);
index 9c2b88d..212d2f5 100644 (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());
 }