adb: fix zero-initialization in Block.

Iccfe3bd4fe45a0319bd9f23b8cbff4c7070c9f4d changed Block from using
malloc to std::make_unique, which does the equivalent of
`new char[size]()`, which value initializes the array members to 0.
Switch to `reset(new char[size])` to avoid this costly initialization.

Test: adb_benchmark
Change-Id: I09aacb949a7bd4a946ce35a8ee65d1f451577b72
This commit is contained in:
Josh Gao 2018-11-12 13:44:38 -08:00
parent 80dd70d285
commit 10d079a37b

View file

@ -108,7 +108,10 @@ struct Block {
CHECK_EQ(0ULL, capacity_);
CHECK_EQ(0ULL, size_);
if (size != 0) {
data_ = std::make_unique<char[]>(size);
// This isn't std::make_unique because that's equivalent to `new char[size]()`, which
// value-initializes the array instead of leaving it uninitialized. As an optimization,
// call new without parentheses to avoid this costly initialization.
data_.reset(new char[size]);
capacity_ = size;
size_ = size;
}