xstrdup: use memcpy

the length is already known, so memcpy should be faster than xstrsncpy.
This commit is contained in:
NRK 2022-08-09 03:01:30 +06:00
parent d49ddd1331
commit f8ee991254
1 changed files with 1 additions and 4 deletions

View File

@ -985,10 +985,7 @@ static char *xstrdup(const char *restrict s)
{
size_t len = xstrlen(s) + 1;
char *ptr = malloc(len);
if (ptr)
xstrsncpy(ptr, s, len);
return ptr;
return ptr ? memcpy(ptr, s, len) : NULL;
}
static bool is_suffix(const char *restrict str, const char *restrict suffix)