From c128213daa677d548bfc2905496257fe4a4faf79 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 11 Mar 2020 21:07:32 +0100 Subject: ft_mem* and ft_strlen optimization --- src/mem/ft_memset.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/mem/ft_memset.c') diff --git a/src/mem/ft_memset.c b/src/mem/ft_memset.c index 89f53ff..ce471a5 100644 --- a/src/mem/ft_memset.c +++ b/src/mem/ft_memset.c @@ -11,21 +11,29 @@ /* ************************************************************************** */ #include "libft.h" +#include "libft_mem.h" void *ft_memset(void *s, int c, size_t n) { - long int buf; - long int *long_s; + uint64_t buf; + void *cpy; - c = (unsigned char)c; - while (n % 8 > 0) - *((t_ftbyte*)s + --n) = c; - buf = (long int)c | (long int)c << 8 | (long int)c << 16 - | (long int)c << 24 | (long int)c << 32 | (long int)c << 40 - | (long int)c << 48 | (long int)c << 56; - n /= 8; - long_s = s; + cpy = s; + c = (uint8_t)c; + buf = (uint64_t)c | (uint64_t)c << 8 | (uint64_t)c << 16 + | (uint64_t)c << 24 | (uint64_t)c << 32 | (uint64_t)c << 40 + | (uint64_t)c << 48 | (uint64_t)c << 56; + while (n > 8) + { + *(uint64_t*)s = buf; + n -= 8; + s += 8; + } while (n > 0) - long_s[--n] = buf; - return (s); + { + *(uint8_t*)s = c; + s++; + n--; + } + return (cpy); } -- cgit