Add resize_initialized and resize_uninitialized to Vector. These functions serve as replacements for resize, to make sure the caller understands whether elements need to be initialized 'by hand' after the call.

This commit is contained in:
Lukas Tenbrink
2025-05-23 00:20:22 +02:00
parent 6c9765d87e
commit 4cb8a0c77e
24 changed files with 62 additions and 44 deletions

View File

@@ -207,7 +207,7 @@ TEST_CASE("[FileAccess] Get/Store floating point half precision values") {
// Data should be empty.
PackedByteArray reference;
reference.resize_zeroed(4096);
reference.resize_initialized(4096);
CHECK(reference == full_data);
f->seek(0);
@@ -215,7 +215,7 @@ TEST_CASE("[FileAccess] Get/Store floating point half precision values") {
CHECK(partial_data.size() == 4095);
CHECK(!f->eof_reached());
reference.resize_zeroed(4095);
reference.resize_initialized(4095);
CHECK(reference == partial_data);
}
}

View File

@@ -133,7 +133,7 @@ TEST_CASE("[PacketPeer][PacketPeerStream] Get packet buffer") {
// First 4 bytes are the length of the string.
CharString cs = godot_rules.ascii();
Vector<uint8_t> buffer = { (uint8_t)(cs.length() + 1), 0, 0, 0 };
buffer.resize_zeroed(4 + cs.length() + 1);
buffer.resize_initialized(4 + cs.length() + 1);
memcpy(buffer.ptrw() + 4, cs.get_data(), cs.length());
spb->set_data_array(buffer);