Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10d079a3 authored by Josh Gao's avatar Josh Gao
Browse files

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
parent 80dd70d2
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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;
        }