diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-11 21:07:32 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-11 21:23:49 +0100 |
| commit | c128213daa677d548bfc2905496257fe4a4faf79 (patch) | |
| tree | d087ceaeff3124ff539bc05d834d79f8187d5628 /src/str/ft_strncmp.c | |
| parent | 3c3f1115f6e9a9b914e2dcbd796501ca7ce85342 (diff) | |
| download | libft-c128213daa677d548bfc2905496257fe4a4faf79.tar.gz libft-c128213daa677d548bfc2905496257fe4a4faf79.tar.bz2 libft-c128213daa677d548bfc2905496257fe4a4faf79.zip | |
ft_mem* and ft_strlen optimization
Diffstat (limited to 'src/str/ft_strncmp.c')
| -rw-r--r-- | src/str/ft_strncmp.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/str/ft_strncmp.c b/src/str/ft_strncmp.c index caa052b..a0371e4 100644 --- a/src/str/ft_strncmp.c +++ b/src/str/ft_strncmp.c @@ -11,16 +11,12 @@ /* ************************************************************************** */ #include "libft.h" -#include "libft_types.h" +#include "libft_str.h" int ft_strncmp(const char *s1, const char *s2, size_t n) { - size_t i; + size_t len; - if (n == 0) - return (0); - i = 0; - while (i + 1 < n && s1[i] == s2[i] && s1[i]) - i++; - return ((t_ftuchar)s1[i] - (t_ftuchar)s2[i]); + len = ft_strlen(s1); + return (ft_memcmp(s1, s2, n < len ? n : len + 1)); } |
