[svn:parrot] r48535 - in branches/substr_eq_at: include/parrot src/string

chromatic at svn.parrot.org chromatic at svn.parrot.org
Mon Aug 16 20:06:04 UTC 2010


Author: chromatic
Date: Mon Aug 16 20:06:04 2010
New Revision: 48535
URL: https://trac.parrot.org/parrot/changeset/48535

Log:
[str] Enabled Unicode in Parrot_str_compare_offset.

This is a proof of concept which needs cleanup, but all tests pass for now.
Ideally the STRING parameters can go const again with some cleverness.

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

Modified: branches/substr_eq_at/include/parrot/string_funcs.h
==============================================================================
--- branches/substr_eq_at/include/parrot/string_funcs.h	Mon Aug 16 19:52:23 2010	(r48534)
+++ branches/substr_eq_at/include/parrot/string_funcs.h	Mon Aug 16 20:06:04 2010	(r48535)
@@ -96,8 +96,8 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 INTVAL Parrot_str_compare_offset(PARROT_INTERP,
-    ARGIN(const STRING *a),
-    ARGIN(const STRING *b),
+    ARGIN(STRING *a),
+    ARGIN(STRING *b),
     INTVAL offset,
     INTVAL length)
         __attribute__nonnull__(1)

Modified: branches/substr_eq_at/src/string/api.c
==============================================================================
--- branches/substr_eq_at/src/string/api.c	Mon Aug 16 19:52:23 2010	(r48534)
+++ branches/substr_eq_at/src/string/api.c	Mon Aug 16 20:06:04 2010	(r48535)
@@ -1328,8 +1328,8 @@
 
 /*
 
-=item C<INTVAL Parrot_str_compare_offset(PARROT_INTERP, const STRING *a, const
-STRING *b, INTVAL offset, INTVAL length)>
+=item C<INTVAL Parrot_str_compare_offset(PARROT_INTERP, STRING *a, STRING *b,
+INTVAL offset, INTVAL length)>
 
 Compares two strings to each other.  If s1 is less than s2, returns -1.  If the
 strings are equal, returns 0.  If s1 is greater than s2, returns 2.  This
@@ -1345,8 +1345,8 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 INTVAL
-Parrot_str_compare_offset(PARROT_INTERP, ARGIN(const STRING *a),
-    ARGIN(const STRING *b), INTVAL offset, INTVAL length)
+Parrot_str_compare_offset(PARROT_INTERP, ARGIN(STRING *a),
+    ARGIN(STRING *b), INTVAL offset, INTVAL length)
 {
     ASSERT_ARGS(Parrot_str_compare_offset)
 
@@ -1358,19 +1358,27 @@
 
     if (a->encoding == b->encoding)
         return memcmp(a->strstart + offset, b->strstart, length);
+    else {
+        /* HEY!  Look over there!  You don't see this!
+         * Stack-allocated STRINGs might be safer anyhow. */
+        char   *a_strstart = a->strstart;
+        UINTVAL a_strlen   = a->strlen;
+        UINTVAL b_strlen   = b->strlen;
+        INTVAL  ret_val    = 0;
+
+        a->strstart += offset;
+        a->strlen   -= offset;
+        a->strlen    = a->strlen > (UINTVAL)length ? length : a->strlen;
+        b->strlen    = b->strlen > (UINTVAL)length ? length : b->strlen;
+
+        ret_val      = CHARSET_COMPARE(interp, a, b);
+
+        a->strstart  = a_strstart;
+        a->strlen    = a_strlen;
+        b->strlen    = b->strlen;
 
-    /* do these make sense? */
-    if (STRING_IS_NULL(b))
-        return a && (a->strlen != 0);
-
-    if (STRING_IS_NULL(a))
-        return -(b->strlen != 0);
-
-    ASSERT_STRING_SANITY(a);
-    ASSERT_STRING_SANITY(b);
-
-    /* XXX: sanitize offset, make length work */
-    return CHARSET_COMPARE_OFFSET(interp, a, b, offset);
+        return ret_val;
+    }
 }
 
 


More information about the parrot-commits mailing list