Add reserve_exact to CowData and Vector.

Change growth factor to be an indeterministic 1.5x.
Use `reserve_exact` in `FileAccess` to reduce on binary file loading RAM usage.

# Conflicts:
#	core/templates/cowdata.h
This commit is contained in:
Lukas Tenbrink 2025-09-25 22:27:52 +02:00
parent d705613db3
commit c993db9688
4 changed files with 78 additions and 82 deletions

View file

@ -569,6 +569,7 @@ Vector<uint8_t> FileAccess::get_buffer(int64_t p_length) const {
return data;
}
data.reserve_exact(p_length);
Error err = data.resize(p_length);
ERR_FAIL_COND_V_MSG(err != OK, data, vformat("Can't resize data to %d elements.", p_length));
@ -863,6 +864,7 @@ Vector<uint8_t> FileAccess::get_file_as_bytes(const String &p_path, Error *r_err
ERR_FAIL_V_MSG(Vector<uint8_t>(), vformat("Can't open file from path '%s'.", String(p_path)));
}
Vector<uint8_t> data;
data.reserve_exact(f->get_length());
data.resize(f->get_length());
f->get_buffer(data.ptrw(), data.size());
return data;