aboutsummaryrefslogtreecommitdiff
path: root/src/mem
diff options
context:
space:
mode:
Diffstat (limited to 'src/mem')
-rw-r--r--src/mem/ft_memchr.c23
-rw-r--r--src/mem/ft_memcpy.c3
2 files changed, 10 insertions, 16 deletions
diff --git a/src/mem/ft_memchr.c b/src/mem/ft_memchr.c
index e0266af..848b436 100644
--- a/src/mem/ft_memchr.c
+++ b/src/mem/ft_memchr.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 09:55:31 by cacharle #+# #+# */
-/* Updated: 2020/04/01 21:50:49 by charles ### ########.fr */
+/* Updated: 2020/05/12 21:39:04 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,16 +27,15 @@ void *ft_memchr(const void *s, int c, size_t n)
uint64_t lw;
c = (uint8_t)c;
- while (((uint64_t)s & 0b111) != 0)
+ while (((uint64_t)s & 0b111) != 0 && n > 0)
{
- n--;
if (*(uint8_t*)s == (uint8_t)c)
- return ((uint8_t*)s);
+ return ((void*)s);
+ n--;
s++;
}
- 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;
+ buf = c | c << 8 | c << 16 | c << 24;
+ buf |= buf << 32;
while (n >= 8)
{
lw = *(uint64_t*)s ^ buf;
@@ -45,12 +44,8 @@ void *ft_memchr(const void *s, int c, size_t n)
n -= 8;
s += 8;
}
- while (n > 0)
- {
- if (*(uint8_t*)s == (uint8_t)c)
- return ((uint8_t*)s);
- n--;
- s++;
- }
+ while (n-- > 0)
+ if (*(uint8_t*)s++ == (uint8_t)c)
+ return ((void*)(s - 1));
return (NULL);
}
diff --git a/src/mem/ft_memcpy.c b/src/mem/ft_memcpy.c
index 1f84bfd..699111f 100644
--- a/src/mem/ft_memcpy.c
+++ b/src/mem/ft_memcpy.c
@@ -6,11 +6,10 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:00:07 by cacharle #+# #+# */
-/* Updated: 2020/01/17 10:39:04 by cacharle ### ########.fr */
+/* Updated: 2020/05/12 20:49:35 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libft.h"
#include "libft_mem.h"
void *ft_memcpy(void *dest, const void *src, size_t n)