[svn:parrot] r45888 - in trunk: include/parrot src/string

bacek at svn.parrot.org bacek at svn.parrot.org
Thu Apr 22 09:44:57 UTC 2010


Author: bacek
Date: Thu Apr 22 09:44:56 2010
New Revision: 45888
URL: https://trac.parrot.org/parrot/changeset/45888

Log:
Constify Parrot_str_replace args.

Modified:
   trunk/include/parrot/string_funcs.h
   trunk/src/string/api.c

Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h	Thu Apr 22 09:28:02 2010	(r45887)
+++ trunk/include/parrot/string_funcs.h	Thu Apr 22 09:44:56 2010	(r45888)
@@ -305,10 +305,10 @@
 PARROT_CAN_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
 STRING * Parrot_str_replace(PARROT_INTERP,
-    ARGIN(STRING *src),
+    ARGIN(const STRING *src),
     INTVAL offset,
     INTVAL length,
-    ARGIN(STRING *rep))
+    ARGIN(const STRING *rep))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2)
         __attribute__nonnull__(5);

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Thu Apr 22 09:28:02 2010	(r45887)
+++ trunk/src/string/api.c	Thu Apr 22 09:44:56 2010	(r45888)
@@ -1094,8 +1094,8 @@
 
 /*
 
-=item C<STRING * Parrot_str_replace(PARROT_INTERP, STRING *src, INTVAL offset,
-INTVAL length, STRING *rep)>
+=item C<STRING * Parrot_str_replace(PARROT_INTERP, const STRING *src, INTVAL
+offset, INTVAL length, const STRING *rep)>
 
 Replaces a sequence of C<length> characters from C<offset> in the first
 Parrot string with the second Parrot string, returning what was
@@ -1121,8 +1121,8 @@
 PARROT_CAN_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
 STRING *
-Parrot_str_replace(PARROT_INTERP, ARGIN(STRING *src),
-    INTVAL offset, INTVAL length, ARGIN(STRING *rep))
+Parrot_str_replace(PARROT_INTERP, ARGIN(const STRING *src),
+    INTVAL offset, INTVAL length, ARGIN(const STRING *rep))
 {
     ASSERT_ARGS(Parrot_str_replace)
     String_iter     iter;
@@ -1162,10 +1162,9 @@
     if (!cs) {
         src = Parrot_utf16_encoding_ptr->to_encoding(interp, src);
         rep = Parrot_utf16_encoding_ptr->to_encoding(interp, rep);
-    }
-    else {
-        src->charset  = cs;
-        src->encoding = enc;
+        /* Remember selected charset and encoding */
+        enc = src->encoding;
+        cs  = src->charset;
     }
 
     /* get byte position of the part that will be replaced */
@@ -1186,8 +1185,9 @@
     /* Now do the replacement */
     dest = Parrot_gc_new_string_header(interp, 0);
 
-    /* Copy encoding/charset/etc */
-    STRUCT_COPY(dest, src);
+    /* Set encoding and charset to compatible */
+    dest->encoding = enc;
+    dest->charset  = cs;
 
     /* Clear COW flag. We own buffer */
     PObj_get_FLAGS(dest) = PObj_is_string_FLAG


More information about the parrot-commits mailing list