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

allison at svn.parrot.org allison at svn.parrot.org
Tue Feb 3 21:21:53 UTC 2009


Author: allison
Date: Tue Feb  3 21:21:53 2009
New Revision: 36338
URL: https://trac.parrot.org/parrot/changeset/36338

Log:
[strings] Make 'Parrot_str_equal' the primary, and have 'Parrot_str_not_equal' call it.

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	Tue Feb  3 21:04:56 2009	(r36337)
+++ trunk/include/parrot/string_funcs.h	Tue Feb  3 21:21:53 2009	(r36338)
@@ -259,6 +259,13 @@
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
+INTVAL Parrot_str_equal(PARROT_INTERP,
+    ARGIN_NULLOK(const STRING *s1),
+    ARGIN_NULLOK(const STRING *s2))
+        __attribute__nonnull__(1);
+
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
 INTVAL Parrot_str_not_equal(PARROT_INTERP,
     ARGIN_NULLOK(const STRING *s1),
     ARGIN_NULLOK(const STRING *s2))
@@ -612,6 +619,8 @@
 #define ASSERT_ARGS_Parrot_str_downcase_inplace __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(s)
+#define ASSERT_ARGS_Parrot_str_equal __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_Parrot_str_not_equal __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_Parrot_str_escape __attribute__unused__ int _ASSERT_ARGS_CHECK = \

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Tue Feb  3 21:04:56 2009	(r36337)
+++ trunk/src/string/api.c	Tue Feb  3 21:21:53 2009	(r36338)
@@ -1459,10 +1459,7 @@
 =item C<INTVAL Parrot_str_not_equal>
 
 Compares two Parrot strings, performing type and encoding conversions if
-necessary.
-
-Note that this function returns 0 if the strings are equal, and non-zero
-otherwise.
+necessary. Returns 1 if the strings are not equal, and 0 otherwise.
 
 =cut
 
@@ -1474,27 +1471,49 @@
 Parrot_str_not_equal(PARROT_INTERP, ARGIN_NULLOK(const STRING *s1), ARGIN_NULLOK(const STRING *s2))
 {
     ASSERT_ARGS(Parrot_str_not_equal)
+    return !Parrot_str_equal(interp, s1, s2);
+}
+
+/*
+
+=item C<INTVAL Parrot_str_equal>
+
+Compares two Parrot strings, performing type and encoding conversions if
+necessary.
+
+Returns 1 if the strings are equal, and 0 otherwise.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
+INTVAL
+Parrot_str_equal(PARROT_INTERP, ARGIN_NULLOK(const STRING *s1), ARGIN_NULLOK(const STRING *s2))
+{
+    ASSERT_ARGS(Parrot_str_equal)
     if ((s1 == s2) || (!s1 && !s2)) {
-        return 0;
+        return 1;
     }
     else if (!s2) {
-        return s1->strlen != 0;
+        return s1->strlen == 0;
     }
     else if (!s1) {
-        return s2->strlen != 0;
+        return s2->strlen == 0;
     }
     else if (s1->strlen != s2->strlen) {
-        return 1;       /* we don't care which is bigger */
+        return 0;       /* we don't care which is bigger */
     }
     else if (s1->hashval != s2->hashval && s1->hashval && s2->hashval) {
-        return 1;
+        return 0;
     }
     else if (!s1->strlen) {   /* s2->strlen is the same here */
-        return 0;
+        return 1;
     }
     /* COWed strings */
     else if (s1->strstart == s2->strstart && s1->bufused == s2->bufused) {
-        return 0;
+        return 1;
     }
 
     /*
@@ -1502,7 +1521,7 @@
      * both strings are non-null
      * both strings have same length
      */
-    return CHARSET_COMPARE(interp, s1, s2);
+    return !CHARSET_COMPARE(interp, s1, s2);
 }
 
 


More information about the parrot-commits mailing list