Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 42b766804 -> fe23648e7


Remove Blob_compare and BB_compare


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/d4665edf
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/d4665edf
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/d4665edf

Branch: refs/heads/master
Commit: d4665edf94bdb5e43b180ca13585b0ff8b520608
Parents: 42b7668
Author: Nick Wellnhofer <wellnho...@aevum.de>
Authored: Wed Dec 9 14:16:51 2015 +0100
Committer: Nick Wellnhofer <wellnho...@aevum.de>
Committed: Wed Dec 9 14:16:51 2015 +0100

----------------------------------------------------------------------
 runtime/core/Clownfish/Blob.c             | 21 +++++++--------------
 runtime/core/Clownfish/Blob.cfh           |  6 ------
 runtime/core/Clownfish/ByteBuf.c          | 21 +++++++--------------
 runtime/core/Clownfish/ByteBuf.cfh        |  6 ------
 runtime/core/Clownfish/Test/TestBlob.c    | 15 ++++++++-------
 runtime/core/Clownfish/Test/TestByteBuf.c | 15 ++++++++-------
 6 files changed, 30 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d4665edf/runtime/core/Clownfish/Blob.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Blob.c b/runtime/core/Clownfish/Blob.c
index 4d3b66b..3e37e0c 100644
--- a/runtime/core/Clownfish/Blob.c
+++ b/runtime/core/Clownfish/Blob.c
@@ -114,25 +114,18 @@ Blob_Equals_Bytes_IMP(Blob *self, const void *bytes, 
size_t size) {
     return SI_equals_bytes(self, bytes, size);
 }
 
-int
-Blob_compare(const void *va, const void *vb) {
-    Blob *a = *(Blob**)va;
-    Blob *b = *(Blob**)vb;
-    const size_t size = a->size < b->size ? a->size : b->size;
+int32_t
+Blob_Compare_To_IMP(Blob *self, Obj *other) {
+    Blob *twin = (Blob*)CERTIFY(other, BLOB);
+    const size_t size = self->size < twin->size ? self->size : twin->size;
 
-    int32_t comparison = memcmp(a->buf, b->buf, size);
+    int32_t comparison = memcmp(self->buf, twin->buf, size);
 
-    if (comparison == 0 && a->size != b->size) {
-        comparison = a->size < b->size ? -1 : 1;
+    if (comparison == 0 && self->size != twin->size) {
+        comparison = self->size < twin->size ? -1 : 1;
     }
 
     return comparison;
 }
 
-int32_t
-Blob_Compare_To_IMP(Blob *self, Obj *other) {
-    CERTIFY(other, BLOB);
-    return Blob_compare(&self, &other);
-}
-
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d4665edf/runtime/core/Clownfish/Blob.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Blob.cfh b/runtime/core/Clownfish/Blob.cfh
index 0be3226..9832c5f 100644
--- a/runtime/core/Clownfish/Blob.cfh
+++ b/runtime/core/Clownfish/Blob.cfh
@@ -44,12 +44,6 @@ public final class Clownfish::Blob inherits Clownfish::Obj {
     public inert Blob*
     init_wrap(Blob *self, const char *buf, size_t size);
 
-    /** Lexical comparison of two Blobs, with level of indirection set to
-     * please qsort and friends.
-     */
-    inert int
-    compare(const void *va, const void *vb);
-
     void*
     To_Host(Blob *self);
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d4665edf/runtime/core/Clownfish/ByteBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/ByteBuf.c b/runtime/core/Clownfish/ByteBuf.c
index 11a0acc..976c64f 100644
--- a/runtime/core/Clownfish/ByteBuf.c
+++ b/runtime/core/Clownfish/ByteBuf.c
@@ -217,25 +217,18 @@ BB_Trusted_Utf8_To_String_IMP(ByteBuf *self) {
     return Str_new_from_trusted_utf8(self->buf, self->size);
 }
 
-int
-BB_compare(const void *va, const void *vb) {
-    ByteBuf *a = *(ByteBuf**)va;
-    ByteBuf *b = *(ByteBuf**)vb;
-    const size_t size = a->size < b->size ? a->size : b->size;
+int32_t
+BB_Compare_To_IMP(ByteBuf *self, Obj *other) {
+    ByteBuf *twin = (ByteBuf*)CERTIFY(other, BYTEBUF);
+    const size_t size = self->size < twin->size ? self->size : twin->size;
 
-    int32_t comparison = memcmp(a->buf, b->buf, size);
+    int32_t comparison = memcmp(self->buf, twin->buf, size);
 
-    if (comparison == 0 && a->size != b->size) {
-        comparison = a->size < b->size ? -1 : 1;
+    if (comparison == 0 && self->size != twin->size) {
+        comparison = self->size < twin->size ? -1 : 1;
     }
 
     return comparison;
 }
 
-int32_t
-BB_Compare_To_IMP(ByteBuf *self, Obj *other) {
-    CERTIFY(other, BYTEBUF);
-    return BB_compare(&self, &other);
-}
-
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d4665edf/runtime/core/Clownfish/ByteBuf.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/ByteBuf.cfh 
b/runtime/core/Clownfish/ByteBuf.cfh
index f6f6233..e154ffd 100644
--- a/runtime/core/Clownfish/ByteBuf.cfh
+++ b/runtime/core/Clownfish/ByteBuf.cfh
@@ -56,12 +56,6 @@ final class Clownfish::ByteBuf nickname BB inherits 
Clownfish::Obj {
     init_steal_bytes(ByteBuf *self, void *bytes, size_t size,
                      size_t capacity);
 
-    /** Lexical comparison of two ByteBufs, with level of indirection set to
-     * please qsort and friends.
-     */
-    inert int
-    compare(const void *va, const void *vb);
-
     void*
     To_Host(ByteBuf *self);
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d4665edf/runtime/core/Clownfish/Test/TestBlob.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestBlob.c 
b/runtime/core/Clownfish/Test/TestBlob.c
index e64e49a..9307f5f 100644
--- a/runtime/core/Clownfish/Test/TestBlob.c
+++ b/runtime/core/Clownfish/Test/TestBlob.c
@@ -75,12 +75,12 @@ test_Clone(TestBatchRunner *runner) {
 }
 
 static void
-test_compare(TestBatchRunner *runner) {
+test_Compare_To(TestBatchRunner *runner) {
     {
         Blob *a = Blob_new("foo", 4);
         Blob *b = Blob_new("foo", 4);
-        TEST_INT_EQ(runner, Blob_compare(&a, &b), 0,
-                    "Blob_compare returns 0 for equal Blobs");
+        TEST_INT_EQ(runner, Blob_Compare_To(a, (Obj*)b), 0,
+                    "Compare_To returns 0 for equal Blobs");
         DECREF(a);
         DECREF(b);
     }
@@ -88,7 +88,8 @@ test_compare(TestBatchRunner *runner) {
     {
         Blob *a = Blob_new("foo", 3);
         Blob *b = Blob_new("foo\0b", 5);
-        TEST_TRUE(runner, Blob_compare(&a, &b) < 0, "shorter Blob sorts 
first");
+        TEST_TRUE(runner, Blob_Compare_To(a, (Obj*)b) < 0,
+                  "shorter Blob sorts first");
         DECREF(a);
         DECREF(b);
     }
@@ -96,8 +97,8 @@ test_compare(TestBatchRunner *runner) {
     {
         Blob *a = Blob_new("foo\0a", 5);
         Blob *b = Blob_new("foo\0b", 5);
-        TEST_TRUE(runner, Blob_compare(&a, &b) < 0,
-                  "NULL doesn't interfere with Blob_compare");
+        TEST_TRUE(runner, Blob_Compare_To(a, (Obj*)b) < 0,
+                  "NULL doesn't interfere with Compare_To");
         DECREF(a);
         DECREF(b);
     }
@@ -108,7 +109,7 @@ TestBlob_Run_IMP(TestBlob *self, TestBatchRunner *runner) {
     TestBatchRunner_Plan(runner, (TestBatch*)self, 11);
     test_Equals(runner);
     test_Clone(runner);
-    test_compare(runner);
+    test_Compare_To(runner);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d4665edf/runtime/core/Clownfish/Test/TestByteBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestByteBuf.c 
b/runtime/core/Clownfish/Test/TestByteBuf.c
index 57238bc..c2f799d 100644
--- a/runtime/core/Clownfish/Test/TestByteBuf.c
+++ b/runtime/core/Clownfish/Test/TestByteBuf.c
@@ -82,22 +82,23 @@ test_Clone(TestBatchRunner *runner) {
 }
 
 static void
-test_compare(TestBatchRunner *runner) {
+test_Compare_To(TestBatchRunner *runner) {
     ByteBuf *a = BB_new_bytes("foo\0a", 5);
     ByteBuf *b = BB_new_bytes("foo\0b", 5);
 
     BB_Set_Size(a, 4);
     BB_Set_Size(b, 4);
-    TEST_INT_EQ(runner, BB_compare(&a, &b), 0,
-                "BB_compare returns 0 for equal ByteBufs");
+    TEST_INT_EQ(runner, BB_Compare_To(a, (Obj*)b), 0,
+                "Compare_To returns 0 for equal ByteBufs");
 
     BB_Set_Size(a, 3);
-    TEST_TRUE(runner, BB_compare(&a, &b) < 0, "shorter ByteBuf sorts first");
+    TEST_TRUE(runner, BB_Compare_To(a, (Obj*)b) < 0,
+              "shorter ByteBuf sorts first");
 
     BB_Set_Size(a, 5);
     BB_Set_Size(b, 5);
-    TEST_TRUE(runner, BB_compare(&a, &b) < 0,
-              "NULL doesn't interfere with BB_compare");
+    TEST_TRUE(runner, BB_Compare_To(a, (Obj*)b) < 0,
+              "NULL doesn't interfere with Compare_To");
 
     DECREF(a);
     DECREF(b);
@@ -172,7 +173,7 @@ TestBB_Run_IMP(TestByteBuf *self, TestBatchRunner *runner) {
     test_Equals(runner);
     test_Grow(runner);
     test_Clone(runner);
-    test_compare(runner);
+    test_Compare_To(runner);
     test_Mimic(runner);
     test_Utf8_To_String(runner);
     test_Cat(runner);

Reply via email to