Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 10d079a

Browse files
committed
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
1 parent 80dd70d commit 10d079a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

adb/types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ struct Block {
108108
CHECK_EQ(0ULL, capacity_);
109109
CHECK_EQ(0ULL, size_);
110110
if (size != 0) {
111-
data_ = std::make_unique<char[]>(size);
111+
// This isn't std::make_unique because that's equivalent to `new char[size]()`, which
112+
// value-initializes the array instead of leaving it uninitialized. As an optimization,
113+
// call new without parentheses to avoid this costly initialization.
114+
data_.reset(new char[size]);
112115
capacity_ = size;
113116
size_ = size;
114117
}

0 commit comments

Comments
 (0)