mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use std::fill_n over memset
parent
92bd78dd25
commit
7981fcb297
|
@ -538,7 +538,7 @@ void SQStringTable::AllocNodes(SQInteger size)
|
|||
{
|
||||
_numofslots = size;
|
||||
_strings = (SQString**)SQ_MALLOC(sizeof(SQString*)*_numofslots);
|
||||
memset(_strings,0,sizeof(SQString*)*(size_t)_numofslots);
|
||||
std::fill_n(_strings, _numofslots, nullptr);
|
||||
}
|
||||
|
||||
static const std::hash<std::string_view> string_table_hash{};
|
||||
|
|
|
@ -43,9 +43,10 @@ void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int s
|
|||
|
||||
void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8_t colour)
|
||||
{
|
||||
std::byte *p = static_cast<std::byte *>(video);
|
||||
do {
|
||||
memset(video, colour, width);
|
||||
video = (uint8_t *)video + _screen.pitch;
|
||||
std::fill_n(p, width, static_cast<std::byte>(colour));
|
||||
p += _screen.pitch;
|
||||
} while (--height);
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ void MxMixSamples(void *buffer, uint samples)
|
|||
}
|
||||
|
||||
/* Clear the buffer */
|
||||
memset(buffer, 0, sizeof(int16_t) * 2 * samples);
|
||||
std::fill_n(static_cast<int16_t *>(buffer), 2 * samples, 0);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{ _music_stream_mutex };
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -448,7 +448,7 @@ static void *ReadRecolourSprite(SpriteFile &file, size_t file_pos, uint num, Spr
|
|||
uint8_t *dest_tmp = new uint8_t[std::max(RECOLOUR_SPRITE_SIZE, num)];
|
||||
|
||||
/* Only a few recolour sprites are less than 257 bytes */
|
||||
if (num < RECOLOUR_SPRITE_SIZE) memset(dest_tmp, 0, RECOLOUR_SPRITE_SIZE);
|
||||
if (num < RECOLOUR_SPRITE_SIZE) std::fill_n(dest_tmp, RECOLOUR_SPRITE_SIZE, 0);
|
||||
file.ReadBlock(dest_tmp, num);
|
||||
|
||||
/* The data of index 0 is never used; "literal 00" according to the (New)GRF specs. */
|
||||
|
|
|
@ -203,7 +203,7 @@ static bool CreateMainSurface(uint w, uint h)
|
|||
_screen.dst_ptr = _allegro_screen->line[0];
|
||||
|
||||
/* Initialise the screen so we don't blit garbage to the screen */
|
||||
memset(_screen.dst_ptr, 0, static_cast<size_t>(_screen.height) * _screen.pitch);
|
||||
std::fill_n(static_cast<std::byte *>(_screen.dst_ptr), static_cast<size_t>(_screen.height) * _screen.pitch, static_cast<std::byte>(0));
|
||||
|
||||
/* Set the mouse at the place where we expect it */
|
||||
poll_mouse();
|
||||
|
|
Loading…
Reference in New Issue