aboutsummaryrefslogtreecommitdiff
path: root/ft_memset.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-21 02:06:06 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-21 02:06:06 +0100
commitafc8c70a66773563f6e7429b500abcbab631722b (patch)
tree731b50b430b493280ce97a557f86f45cb2f37780 /ft_memset.c
parentf96be9ba455b0a71562e732664717b507b4bd548 (diff)
downloadlibft-afc8c70a66773563f6e7429b500abcbab631722b.tar.gz
libft-afc8c70a66773563f6e7429b500abcbab631722b.tar.bz2
libft-afc8c70a66773563f6e7429b500abcbab631722b.zip
ft_memset and ft_strlen optimization
Diffstat (limited to 'ft_memset.c')
-rw-r--r--ft_memset.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/ft_memset.c b/ft_memset.c
index cd7616c..7963fd0 100644
--- a/ft_memset.c
+++ b/ft_memset.c
@@ -6,15 +6,26 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:01:23 by cacharle #+# #+# */
-/* Updated: 2019/11/20 03:22:29 by cacharle ### ########.fr */
+/* Updated: 2019/11/20 23:22:51 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
+#define BUF_TYPE long int
+
void *ft_memset(void *s, int c, size_t n)
{
- while (n-- > 0)
- *((t_byte*)s + n) = (t_byte)c;
+ BUF_TYPE buf;
+
+ c = (unsigned char)c;
+ while (n % 8 > 0)
+ *((t_byte*)s + --n) = (t_byte)c;
+ n /= 8;
+ buf = (BUF_TYPE)c | (BUF_TYPE)c << 8 | (BUF_TYPE)c << 16
+ | (BUF_TYPE)c << 24 | (BUF_TYPE)c << 32 | (BUF_TYPE)c << 40
+ | (BUF_TYPE)c << 48 | (BUF_TYPE)c << 56;
+ while (n > 0)
+ *((BUF_TYPE*)s + --n) = buf;
return (s);
}