From dd0afe9abdbfe678188407da935692d094fe1672 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 29 Jan 2023 21:40:19 +0100 Subject: 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 --- include/c/str/cpy/stp/stpe/stpecpy.h | 6 ++---- 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 #include -#include #include +#include #include @@ -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 #include -#include #include +#include #include @@ -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 -- cgit v1.2.3