1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 08:52:40 +01:00

Codechange: use std::fill_n over memset

This commit is contained in:
Rubidium
2025-05-06 22:35:24 +02:00
committed by rubidium42
parent 92bd78dd25
commit 7981fcb297
6 changed files with 9 additions and 8 deletions

View File

@@ -281,15 +281,15 @@ static std::optional<std::vector<uint32_t>> ParseIntList(std::string_view str)
static bool LoadIntList(std::optional<std::string_view> str, void *array, int nelems, VarType type)
{
size_t elem_size = SlVarSize(type);
std::byte *p = static_cast<std::byte *>(array);
if (!str.has_value()) {
memset(array, 0, nelems * elem_size);
std::fill_n(p, nelems * elem_size, static_cast<std::byte>(0));
return true;
}
auto opt_items = ParseIntList(*str);
if (!opt_items.has_value() || opt_items->size() != (size_t)nelems) return false;
std::byte *p = static_cast<std::byte *>(array);
for (auto item : *opt_items) {
WriteValue(p, type, item);
p += elem_size;