diff options
author | Alejandro Colomar <alx@kernel.org> | 2023-01-29 21:40:19 +0100 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-01-29 21:40:20 +0100 |
commit | dd0afe9abdbfe678188407da935692d094fe1672 (patch) | |
tree | b17dfa847158bbdbb0f07172cc4fee95633b626d | |
parent | 1c6a14df47f5f8d90e77dd6c7702970039f107ea (diff) |
Microoptimize and simplify some functions
Copying the NUL after the call to mempcpy(3) reduces the need to add an
offset to the pointer. Also, we can call a function that does exactly
that, thus reducing the source code.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | include/c/str/cpy/stp/stpe/stpecpy.h | 6 | ||||
-rw-r--r-- | include/c/str/cpy/stp/stpe/ustr2stpe.h | 6 |
2 files changed, 4 insertions, 8 deletions
diff --git a/include/c/str/cpy/stp/stpe/stpecpy.h b/include/c/str/cpy/stp/stpe/stpecpy.h index c09a7ab..d75b2b0 100644 --- a/include/c/str/cpy/stp/stpe/stpecpy.h +++ b/include/c/str/cpy/stp/stpe/stpecpy.h @@ -11,8 +11,8 @@ #include <c/branch/likely.h> #include <c/branch/unreachable.h> -#include <c/mem/cpy/mempcpy.h> #include <c/qual/nullable/nullable.h> +#include <c/str/cpy/stp/stp/ustr2stp.h> #include <c/str/len/strlen.h> @@ -37,9 +37,7 @@ c_stpecpy(char *c_nullable dst, char *end, const char *restrict src) slen = c_strnlen(src, dsize); trunc = (slen == dsize); dlen = slen - trunc; - dst[dlen] = '\0'; - - return c_mempcpy(dst, src, dlen) + trunc; + return c_ustr2stp(dst, src, dlen) + trunc; } #pragma clang assume_nonnull end diff --git a/include/c/str/cpy/stp/stpe/ustr2stpe.h b/include/c/str/cpy/stp/stpe/ustr2stpe.h index 87c2065..691781b 100644 --- a/include/c/str/cpy/stp/stpe/ustr2stpe.h +++ b/include/c/str/cpy/stp/stpe/ustr2stpe.h @@ -12,8 +12,8 @@ #include <c/branch/likely.h> #include <c/branch/unreachable.h> -#include <c/mem/cpy/mempcpy.h> #include <c/qual/nullable/nullable.h> +#include <c/str/cpy/stp/stp/ustr2stp.h> #include <c/str/len/strlen.h> @@ -38,9 +38,7 @@ c_ustr2stpe(char *c_nullable dst, char *end, const char *restrict src, dsize = end - dst; trunc = (slen > dsize - 1); dlen = MIN(slen, dsize - 1); - dst[dlen] = '\0'; - - return c_mempcpy(dst, src, dlen) + trunc; + return c_ustr2stp(dst, src, dlen) + trunc; } #pragma clang assume_nonnull end |