[Spice-commits] common/mem.c

Frediano Ziglio fziglio at kemper.freedesktop.org
Tue Jan 26 09:17:34 PST 2016


 common/mem.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

New commits:
commit 7790dacfd3fe0b6624f64260ed5e7375dcf06aae
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jan 26 16:34:55 2016 +0000

    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 at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/common/mem.c b/common/mem.c
index 2fda6f3..e430b5d 100644
--- a/common/mem.c
+++ b/common/mem.c
@@ -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;
 }
 


More information about the Spice-commits mailing list