# New Ticket Created by  NotFound 
# Please include the string:  [perl #56750]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=56750 >


This patch adds a function to create empty strings, and replaces with
it a lot of CONST_STRING and const_string usages with ""

The rationale is that the const_string functions and macros creates a
string header and do several other things, but the empty string just
needs to create the header. Also, the string created that way don't
need uncow operations to be modified, and does not lose nothing by not
being cow'ed if not modified.

I expect to hear some comments before commiting it, however.

-- 
Salu2
Index: src/string.c
===================================================================
--- src/string.c	(revisión: 29201)
+++ src/string.c	(copia de trabajo)
@@ -204,6 +204,27 @@
 
 /*
 
+=item C<STRING * Parrot_string_empty>
+
+Returns an empty string.
+
+= cut
+
+*/
+
+PARROT_API
+PARROT_CANNOT_RETURN_NULL
+STRING *
+Parrot_string_empty(PARROT_INTERP)
+{
+    STRING * const s = new_string_header(interp, 0);
+    s->encoding      = PARROT_DEFAULT_ENCODING;
+    s->charset       = PARROT_DEFAULT_CHARSET;
+    return s;
+}
+
+/*
+
 =item C<STRING * string_set>
 
 Makes the contents of first Parrot string a copy of the contents of
@@ -277,6 +298,7 @@
         return;
     }
 
+
     interp->const_cstring_table =
         mem_allocate_n_zeroed_typed(n_parrot_cstrings, STRING *);
 
Index: src/inter_misc.c
===================================================================
--- src/inter_misc.c	(revisión: 29201)
+++ src/inter_misc.c	(copia de trabajo)
@@ -461,7 +461,7 @@
         case CPU_ARCH:
         case CPU_TYPE:
         default:
-            return CONST_STRING(interp, "");
+            return Parrot_string_empty(interp);
     }
 }
 
Index: src/pmc/role.pmc
===================================================================
--- src/pmc/role.pmc	(revisión: 29201)
+++ src/pmc/role.pmc	(copia de trabajo)
@@ -228,7 +228,7 @@
         PObj_active_destroy_SET(SELF);
 
         /* Set up the object. */
-        role->name            = CONST_STRING(interp, "");
+        role->name            = Parrot_string_empty(interp);
         role->_namespace      = PMCNULL;
         role->roles           = pmc_new(interp, enum_class_ResizablePMCArray);
         role->methods         = pmc_new(interp, enum_class_Hash);
Index: src/pmc/class.pmc
===================================================================
--- src/pmc/class.pmc	(revisión: 29201)
+++ src/pmc/class.pmc	(copia de trabajo)
@@ -460,7 +460,7 @@
 
         /* Set up the object. */
         PMC_data(SELF)          = _class;
-        _class->name            = CONST_STRING(interp, "");
+        _class->name            = Parrot_string_empty(interp);
         _class->_namespace      = PMCNULL;
         _class->parents         = pmc_new(interp, enum_class_ResizablePMCArray);
         _class->all_parents     = pmc_new(interp, enum_class_ResizablePMCArray);
@@ -956,7 +956,7 @@
 
         Parrot_Class * const new_class = PARROT_CLASS(copy);
 
-        new_class->name                = CONST_STRING(interp, "");
+        new_class->name                = Parrot_string_empty(interp);
         new_class->_namespace          = PMCNULL;
         new_class->parents             = VTABLE_clone(interp, _class->parents);
         new_class->roles               = VTABLE_clone(interp, _class->roles);
@@ -1385,7 +1385,7 @@
     VTABLE void freeze(visit_info *info) {
         IMAGE_IO     * const io         = info->image_io;
         Parrot_Class * const class_data = PARROT_CLASS(SELF);
-        STRING       *serial_namespace  = CONST_STRING(interp, "");
+        STRING       *serial_namespace  = Parrot_string_empty(interp);
 
         /* 1) freeze class id */
         VTABLE_push_integer(INTERP, io, class_data->id);
Index: src/pmc/exporter.pmc
===================================================================
--- src/pmc/exporter.pmc	(revisión: 29201)
+++ src/pmc/exporter.pmc	(copia de trabajo)
@@ -249,7 +249,7 @@
         STRING          *s_hash = CONST_STRING(interp, "hash");
 
         if (got_glb) {
-            STRING * const s_empty      = CONST_STRING(interp, "");
+            STRING * const s_empty      = Parrot_string_empty(interp);
             PMC           *temp_globals = pmc_new(interp, enum_class_Hash);
 
             if (PMC_IS_NULL(glb)) {
Index: src/pmc/eventhandler.pmc
===================================================================
--- src/pmc/eventhandler.pmc	(revisión: 29201)
+++ src/pmc/eventhandler.pmc	(copia de trabajo)
@@ -196,7 +196,7 @@
         if (e)
             return string_copy(INTERP, e->type);
 
-        return CONST_STRING(INTERP, "");
+        return Parrot_string_empty(INTERP);
     }
 
 /*
Index: src/pmc/env.pmc
===================================================================
--- src/pmc/env.pmc	(revisión: 29201)
+++ src/pmc/env.pmc	(copia de trabajo)
@@ -145,7 +145,7 @@
     VTABLE STRING *get_string_keyed(PMC *key) {
         if ((PObj_get_FLAGS(key) & KEY_type_FLAGS) == KEY_integer_FLAG) {
             if (PMC_int_val(key) < 0 || PMC_int_val(key) >= SELF.elements()) {
-                return CONST_STRING(interp, "");
+                return Parrot_string_empty(interp);
             }
             else {
                 const char * const envp = environ[PMC_int_val(key)];
@@ -174,7 +174,7 @@
                 }
             }
 
-            return CONST_STRING(interp, "");
+            return Parrot_string_empty(interp);
         }
     }
 
@@ -209,7 +209,7 @@
         }
 
         if (!retval)
-            retval = CONST_STRING(INTERP, "");
+            retval = Parrot_string_empty(INTERP);
 
         return_pmc = pmc_new(INTERP, enum_class_String);
 
Index: src/pmc/task.pmc
===================================================================
--- src/pmc/task.pmc	(revisión: 29201)
+++ src/pmc/task.pmc	(copia de trabajo)
@@ -53,8 +53,8 @@
         /* Set up the core struct. */
         PMC_data(SELF)           = core_struct;
         core_struct->id          = 0;
-        core_struct->type        = CONST_STRING(interp, "");
-        core_struct->subtype     = CONST_STRING(interp, "");
+        core_struct->type        = Parrot_string_empty(interp);
+        core_struct->subtype     = Parrot_string_empty(interp);
         core_struct->priority    = 0;
         core_struct->status      = CONST_STRING(interp, "created");
         core_struct->birthtime   = 0.0;
@@ -142,13 +142,13 @@
         if (! PMC_IS_NULL(elem))
             core_struct->type = VTABLE_get_string(INTERP, elem);
         else
-            core_struct->type = CONST_STRING(INTERP, "");
+            core_struct->type = Parrot_string_empty(INTERP);
 
         elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "subtype"));
         if (! PMC_IS_NULL(elem))
             core_struct->subtype = VTABLE_get_string(INTERP, elem);
         else
-            core_struct->subtype = CONST_STRING(INTERP, "");
+            core_struct->subtype = Parrot_string_empty(INTERP);
 
         elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "priority"));
         if (! PMC_IS_NULL(elem))
Index: src/pmc/timer.pmc
===================================================================
--- src/pmc/timer.pmc	(revisión: 29201)
+++ src/pmc/timer.pmc	(copia de trabajo)
@@ -95,7 +95,7 @@
         PMC_data(SELF)           = core_struct;
         core_struct->id          = 0;
         core_struct->type        = CONST_STRING(interp, "timer");
-        core_struct->subtype     = CONST_STRING(interp, "");
+        core_struct->subtype     = Parrot_string_empty(interp);
         core_struct->priority    = 0;
         core_struct->status      = CONST_STRING(interp, "created");
         core_struct->birthtime   = 0.0;
Index: src/pmc/fixedpmcarray.pmc
===================================================================
--- src/pmc/fixedpmcarray.pmc	(revisión: 29201)
+++ src/pmc/fixedpmcarray.pmc	(copia de trabajo)
@@ -281,7 +281,7 @@
         PMC * const tempPMC = SELF.get_pmc_keyed_int(key);
 
         if (PMC_IS_NULL(tempPMC))
-            return CONST_STRING(interp, "");
+            return Parrot_string_empty(interp);
 
         return VTABLE_get_string(INTERP, tempPMC);
     }
Index: src/pmc/codestring.pmc
===================================================================
--- src/pmc/codestring.pmc	(revisión: 29201)
+++ src/pmc/codestring.pmc	(copia de trabajo)
@@ -216,7 +216,7 @@
     STRING *close_bracket = CONST_STRING(INTERP, "]");
     STRING *s_array       = CONST_STRING(INTERP, "array");
     STRING *prefix        = open_bracket;
-    STRING *out           = CONST_STRING(INTERP, "");
+    STRING *out           = Parrot_string_empty(INTERP);
     INTVAL elements, index;
 
     elements     = VTABLE_elements(INTERP, args);
Index: src/pmc/pmcproxy.pmc
===================================================================
--- src/pmc/pmcproxy.pmc	(revisión: 29201)
+++ src/pmc/pmcproxy.pmc	(copia de trabajo)
@@ -87,7 +87,7 @@
 
         /* Set up the object. */
         _pmc->id               = 0;
-        _pmc->name             = CONST_STRING(interp, "");
+        _pmc->name             = Parrot_string_empty(interp);
         _pmc->_namespace       = PMCNULL;
         _pmc->parents          = pmc_new(interp, enum_class_ResizablePMCArray);
         _pmc->all_parents      = pmc_new(interp, enum_class_ResizablePMCArray);
Index: src/pmc/schedulermessage.pmc
===================================================================
--- src/pmc/schedulermessage.pmc	(revisión: 29201)
+++ src/pmc/schedulermessage.pmc	(copia de trabajo)
@@ -47,7 +47,7 @@
         /* Set up the core struct. */
         PMC_data(SELF)           = core_struct;
         core_struct->id          = 0;
-        core_struct->type        = CONST_STRING(INTERP, "");
+        core_struct->type        = Parrot_string_empty(INTERP);
         core_struct->data        = PMCNULL;
     }
 
Index: src/pmc/key.pmc
===================================================================
--- src/pmc/key.pmc	(revisión: 29201)
+++ src/pmc/key.pmc	(copia de trabajo)
@@ -147,7 +147,7 @@
         if (PObj_get_FLAGS(SELF) & KEY_type_FLAGS)
             return key_string(INTERP, SELF);
 
-        return CONST_STRING(INTERP, "");
+        return Parrot_string_empty(INTERP);
     }
 
 /*
Index: src/pmc/sub.pmc
===================================================================
--- src/pmc/sub.pmc	(revisión: 29201)
+++ src/pmc/sub.pmc	(copia de trabajo)
@@ -492,7 +492,7 @@
 
         hll_name = Parrot_get_HLL_name(INTERP, sub->HLL_id);
         if (!hll_name)
-            hll_name = CONST_STRING(INTERP, "");
+            hll_name = Parrot_string_empty(INTERP);
 
         VTABLE_push_string(INTERP, io, hll_name);
 
@@ -503,7 +503,7 @@
             VTABLE_push_integer(INTERP, io, sub->n_regs_used[i]);
 
         if (!sub->lexid)
-            sub->lexid = CONST_STRING(INTERP, "");
+            sub->lexid = Parrot_string_empty(INTERP);
         VTABLE_push_string(INTERP, io, sub->lexid);
     }
 
Index: src/pmc/parrotio.pmc
===================================================================
--- src/pmc/parrotio.pmc	(revisión: 29201)
+++ src/pmc/parrotio.pmc	(copia de trabajo)
@@ -493,7 +493,7 @@
                 if (last)
                     return string_from_cstring(INTERP, last->name, 0);
 
-                return CONST_STRING(INTERP, "");
+                return Parrot_string_empty(INTERP);
             }
 
             for (++n; n && layer; layer = layer->down, ++n)
@@ -503,7 +503,7 @@
                 return string_from_cstring(INTERP, layer->name, 0);
         }
 
-        return CONST_STRING(INTERP, "");
+        return Parrot_string_empty(INTERP);
     }
 /*
 
Index: src/library.c
===================================================================
--- src/library.c	(revisión: 29201)
+++ src/library.c	(copia de trabajo)
@@ -175,7 +175,7 @@
             PARROT_LIB_PATH_DYNEXT, paths);
     entry = CONST_STRING(interp, "runtime/parrot/dynext/");
     VTABLE_push_string(interp, paths, entry);
-    entry = CONST_STRING(interp, "");
+    entry = Parrot_string_empty(interp);
     VTABLE_push_string(interp, paths, entry);
     entry = CONST_STRING(interp, "lib/parrot/dynext/");
     VTABLE_push_string(interp, paths, entry);
Index: src/dynpmc/gdbmhash.pmc
===================================================================
--- src/dynpmc/gdbmhash.pmc	(revisión: 29201)
+++ src/dynpmc/gdbmhash.pmc	(copia de trabajo)
@@ -222,9 +222,9 @@
         datum key_gdbm, val_gdbm;
 
         if (!key)
-            return CONST_STRING(INTERP, "");
+            return Parrot_string_empty(INTERP);
         if (!dbf)
-            return CONST_STRING(INTERP, "");
+            return Parrot_string_empty(INTERP);
         keystr = make_hash_key(interp, key);
 
         key_gdbm.dsize = keystr->strlen;
Index: include/parrot/string_funcs.h
===================================================================
--- include/parrot/string_funcs.h	(revisión: 29201)
+++ include/parrot/string_funcs.h	(copia de trabajo)
@@ -59,6 +59,11 @@
         __attribute__nonnull__(2);
 
 PARROT_API
+PARROT_CANNOT_RETURN_NULL
+STRING * Parrot_string_empty(PARROT_INTERP)
+        __attribute__nonnull__(1);
+
+PARROT_API
 PARROT_WARN_UNUSED_RESULT
 INTVAL Parrot_string_find_cclass(PARROT_INTERP,
     INTVAL flags,
@@ -87,6 +92,14 @@
 
 PARROT_API
 PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC* Parrot_string_split(PARROT_INTERP,
+    ARGIN_NULLOK(STRING *delim),
+    ARGIN_NULLOK(STRING *str))
+        __attribute__nonnull__(1);
+
+PARROT_API
+PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
 STRING* Parrot_string_trans_charset(PARROT_INTERP,
     ARGMOD_NULLOK(STRING *src),
@@ -426,14 +439,6 @@
 
 PARROT_API
 PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC* Parrot_string_split(PARROT_INTERP,
-    ARGIN_NULLOK(STRING *delim),
-    ARGIN_NULLOK(STRING *str))
-        __attribute__nonnull__(1);
-
-PARROT_API
-PARROT_WARN_UNUSED_RESULT
 INTVAL string_str_index(PARROT_INTERP,
     ARGIN(const STRING *s),
     ARGIN(const STRING *s2),
Index: languages/pipp/src/pmc/phpboolean.pmc
===================================================================
--- languages/pipp/src/pmc/phpboolean.pmc	(revisión: 29201)
+++ languages/pipp/src/pmc/phpboolean.pmc	(copia de trabajo)
@@ -54,7 +54,7 @@
         if (PMC_int_val(SELF))
             return const_string(INTERP, "1");
         else
-            return const_string(INTERP, "");
+            return Parrot_string_empty(INTERP);
     }
 
 

Reply via email to