develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35190 - trunk/src/charset

From:
infinoid
Date:
January 7, 2009 22:53
Subject:
[svn:parrot] r35190 - trunk/src/charset
Message ID:
20090108065320.44A78CB9F9@x12.develooper.com
Author: infinoid
Date: Wed Jan  7 22:53:19 2009
New Revision: 35190

Modified:
   trunk/src/charset/binary.c

Log:
Make a first stab at implementing compare() for the binary charset plugin.

Modified: trunk/src/charset/binary.c
==============================================================================
--- trunk/src/charset/binary.c	(original)
+++ trunk/src/charset/binary.c	Wed Jan  7 22:53:19 2009
@@ -345,17 +345,22 @@
 
 =item C<static INTVAL compare>
 
-Returns 0. We can't directly compare two binary buffers (yet).
+Compare the two buffers, first by size, then with memcmp.
 
 =cut
 
 */
 
 static INTVAL
-compare(SHIM_INTERP, SHIM(const STRING *lhs), SHIM(const STRING *rhs))
+compare(SHIM_INTERP, ARGIN(const STRING *lhs), ARGIN(const STRING *rhs))
 {
     ASSERT_ARGS(compare)
-    return 0;
+    const UINTVAL l_len = lhs->strlen;
+    const UINTVAL r_len = rhs->strlen;
+    if (l_len != r_len)
+        return l_len - r_len;
+
+    return memcmp(lhs->strstart, rhs->strstart, l_len);
 }
 
 /*



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About