Skip to content

Commit

Permalink
xstrdup: use memcpy
Browse files Browse the repository at this point in the history
the length is already known, so memcpy should be faster than xstrsncpy.
  • Loading branch information
N-R-K committed Aug 16, 2022
1 parent d49ddd1 commit f8ee991
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f8ee991

Please sign in to comment.