Micro-optimize clearing of lines

Use a doubling strategy to memset arrays to a fixed value. Makes the
memset O(log(N)) from O(N) in number of calls to memcpy.
This commit is contained in:
Kovid Goyal
2024-01-20 13:19:09 +05:30
parent d0621cb82a
commit 06da31019c
3 changed files with 18 additions and 10 deletions

View File

@@ -427,3 +427,13 @@ SPRITE_MAP_HANDLE alloc_sprite_map(unsigned int, unsigned int);
SPRITE_MAP_HANDLE free_sprite_map(SPRITE_MAP_HANDLE);
const char* get_hyperlink_for_id(const HYPERLINK_POOL_HANDLE, hyperlink_id_type id, bool only_url);
void log_event(const char *format, ...) __attribute__((format(printf, 1, 2)));
#define memset_array(array, val, count) if ((count) > 0) { \
(array)[0] = (val); \
size_t __copied__ = 1; \
while (__copied__ < (count)) { \
const size_t __num__ = MIN(__copied__, (count) - __copied__); \
memcpy((array) + __copied__, (array), __num__ * sizeof((val))); \
__copied__ += __num__; \
} \
}