[svn:parrot] r48856 - trunk/src/string

nwellnhof at svn.parrot.org nwellnhof at svn.parrot.org
Wed Sep 8 15:07:52 UTC 2010


Author: nwellnhof
Date: Wed Sep  8 15:07:52 2010
New Revision: 48856
URL: https://trac.parrot.org/parrot/changeset/48856

Log:
[str] Don't allocate empty string storage

Modified:
   trunk/src/string/api.c

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Wed Sep  8 14:19:06 2010	(r48855)
+++ trunk/src/string/api.c	Wed Sep  8 15:07:52 2010	(r48856)
@@ -324,14 +324,16 @@
     const size_t alloc_size = s->bufused;
     STRING * const result = Parrot_gc_new_string_header(interp, 0);
 
-    /* Allocate new chunk of memory */
-    Parrot_gc_allocate_string_storage(interp, result, alloc_size);
+    if (alloc_size) {
+        /* Allocate new chunk of memory */
+        Parrot_gc_allocate_string_storage(interp, result, alloc_size);
 
-    /* and copy it over */
-    mem_sys_memcopy(result->strstart, s->strstart, alloc_size);
+        /* and copy it over */
+        mem_sys_memcopy(result->strstart, s->strstart, alloc_size);
+    }
 
+    result->bufused  = alloc_size;
     result->strlen   = s->strlen;
-    result->bufused  = s->bufused;
     result->hashval  = s->hashval;
     result->encoding = s->encoding;
 
@@ -658,7 +660,7 @@
 
     Parrot_gc_allocate_string_storage(interp, s, len);
 
-    if (buffer) {
+    if (buffer && len) {
         mem_sys_memcopy(s->strstart, buffer, len);
         s->bufused = len;
         if (encoding->max_bytes_per_codepoint == 1)


More information about the parrot-commits mailing list