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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user