small spice_strdup optimization

avoid to compute the string length twice and use memcpy instead of
strcpy which is faster not having to check for terminator.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Frediano Ziglio 2016-01-26 16:34:55 +00:00
parent 5376f1d88c
commit 7790dacfd3

View File

@ -46,13 +46,15 @@ size_t spice_strnlen(const char *str, size_t max_len)
char *spice_strdup(const char *str)
{
char *copy;
size_t len;
if (str == NULL) {
return NULL;
}
copy = (char *)spice_malloc(strlen(str) + 1);
strcpy(copy, str);
len = strlen(str) + 1;
copy = (char *)spice_malloc(len);
memcpy(copy, str, len);
return copy;
}