mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-common
synced 2026-01-07 11:32:59 +00:00
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:
parent
5376f1d88c
commit
7790dacfd3
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user