Remove BB_Mimic and BB_Mimic_Bytes It can be replaced with BB_Set_Size(bb, 0) followed by BB_Cat_*.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/c8c942d3 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/c8c942d3 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/c8c942d3 Branch: refs/heads/master Commit: c8c942d3231345da5e9ba5ea38c9af18b82152d2 Parents: d4665ed Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Wed Dec 9 14:29:46 2015 +0100 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Wed Dec 9 14:29:46 2015 +0100 ---------------------------------------------------------------------- runtime/core/Clownfish/ByteBuf.c | 27 -------- runtime/core/Clownfish/ByteBuf.cfh | 6 -- runtime/core/Clownfish/Test/TestByteBuf.c | 89 ++++++++++---------------- runtime/go/clownfish/bytebuf_test.go | 11 ---- runtime/perl/t/binding/022-bytebuf.t | 5 +- 5 files changed, 36 insertions(+), 102 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c8c942d3/runtime/core/Clownfish/ByteBuf.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/ByteBuf.c b/runtime/core/Clownfish/ByteBuf.c index 976c64f..3ab5ddd 100644 --- a/runtime/core/Clownfish/ByteBuf.c +++ b/runtime/core/Clownfish/ByteBuf.c @@ -132,33 +132,6 @@ BB_Equals_Bytes_IMP(ByteBuf *self, const void *bytes, size_t size) { } static CFISH_INLINE void -SI_mimic_bytes(ByteBuf *self, const void *bytes, size_t size) { - if (size > self->cap) { S_grow(self, size); } - memmove(self->buf, bytes, size); - self->size = size; -} - -void -BB_Mimic_Bytes_IMP(ByteBuf *self, const void *bytes, size_t size) { - SI_mimic_bytes(self, bytes, size); -} - -void -BB_Mimic_IMP(ByteBuf *self, Obj *other) { - if (Obj_is_a(other, BYTEBUF)) { - ByteBuf *twin = (ByteBuf*)other; - SI_mimic_bytes(self, twin->buf, twin->size); - } - else if (Obj_is_a(other, STRING)) { - String *string = (String*)other; - SI_mimic_bytes(self, Str_Get_Ptr8(string), Str_Get_Size(string)); - } - else { - THROW(ERR, "ByteBuf can't mimic %o", Obj_get_class_name(other)); - } -} - -static CFISH_INLINE void SI_cat_bytes(ByteBuf *self, const void *bytes, size_t size) { const size_t new_size = self->size + size; if (new_size > self->cap) { http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c8c942d3/runtime/core/Clownfish/ByteBuf.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/ByteBuf.cfh b/runtime/core/Clownfish/ByteBuf.cfh index e154ffd..8cf5e49 100644 --- a/runtime/core/Clownfish/ByteBuf.cfh +++ b/runtime/core/Clownfish/ByteBuf.cfh @@ -80,12 +80,6 @@ final class Clownfish::ByteBuf nickname BB inherits Clownfish::Obj { size_t Get_Capacity(ByteBuf *self); - public void - Mimic(ByteBuf *self, Obj *other); - - void - Mimic_Bytes(ByteBuf *self, const void *bytes, size_t size); - /** Concatenate the passed-in bytes onto the end of the ByteBuf. Allocate * more memory as needed. */ http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c8c942d3/runtime/core/Clownfish/Test/TestByteBuf.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestByteBuf.c b/runtime/core/Clownfish/Test/TestByteBuf.c index c2f799d..6e8063c 100644 --- a/runtime/core/Clownfish/Test/TestByteBuf.c +++ b/runtime/core/Clownfish/Test/TestByteBuf.c @@ -36,29 +36,37 @@ TestBB_new() { static void test_Equals(TestBatchRunner *runner) { - ByteBuf *wanted = BB_new_bytes("foo", 4); // Include terminating NULL. - ByteBuf *got = BB_new_bytes("foo", 4); + ByteBuf *bb = BB_new_bytes("foo", 4); // Include terminating NULL. - TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Equals"); + { + ByteBuf *other = BB_new_bytes("foo", 4); + TEST_TRUE(runner, BB_Equals(bb, (Obj*)other), "Equals"); + DECREF(other); + } - TEST_TRUE(runner, BB_Equals_Bytes(got, "foo", 4), "Equals_Bytes"); - TEST_FALSE(runner, BB_Equals_Bytes(got, "foo", 3), + TEST_TRUE(runner, BB_Equals_Bytes(bb, "foo", 4), "Equals_Bytes"); + TEST_FALSE(runner, BB_Equals_Bytes(bb, "foo", 3), "Equals_Bytes spoiled by different size"); - TEST_FALSE(runner, BB_Equals_Bytes(got, "bar", 4), + TEST_FALSE(runner, BB_Equals_Bytes(bb, "bar", 4), "Equals_Bytes spoiled by different content"); - BB_Set_Size(got, 3); - TEST_FALSE(runner, BB_Equals(wanted, (Obj*)got), - "Different size spoils Equals"); + { + ByteBuf *other = BB_new_bytes("foo", 3); + TEST_FALSE(runner, BB_Equals(bb, (Obj*)other), + "Different size spoils Equals"); + DECREF(other); + } - BB_Mimic_Bytes(got, "bar", 4); - TEST_INT_EQ(runner, BB_Get_Size(wanted), BB_Get_Size(got), - "same length"); - TEST_FALSE(runner, BB_Equals(wanted, (Obj*)got), - "Different content spoils Equals"); + { + ByteBuf *other = BB_new_bytes("bar", 4); + TEST_INT_EQ(runner, BB_Get_Size(bb), BB_Get_Size(other), + "same length"); + TEST_FALSE(runner, BB_Equals(bb, (Obj*)other), + "Different content spoils Equals"); + DECREF(other); + } - DECREF(got); - DECREF(wanted); + DECREF(bb); } static void @@ -105,46 +113,20 @@ test_Compare_To(TestBatchRunner *runner) { } static void -test_Mimic(TestBatchRunner *runner) { - ByteBuf *a = BB_new_bytes("foo", 3); - ByteBuf *b = BB_new(0); - - BB_Mimic(b, (Obj*)a); - TEST_TRUE(runner, BB_Equals(a, (Obj*)b), "Mimic"); - - BB_Mimic_Bytes(a, "bar", 4); - TEST_TRUE(runner, strcmp(BB_Get_Buf(a), "bar") == 0, - "Mimic_Bytes content"); - TEST_INT_EQ(runner, BB_Get_Size(a), 4, "Mimic_Bytes size"); - - BB_Mimic(b, (Obj*)a); - TEST_TRUE(runner, BB_Equals(a, (Obj*)b), "Mimic"); - - String *string = Str_newf("baz"); - BB_Mimic(b, (Obj*)string); - DECREF(string); - TEST_TRUE(runner, BB_Equals_Bytes(b, "baz", 3), "Mimic String"); - - DECREF(a); - DECREF(b); -} - -static void test_Cat(TestBatchRunner *runner) { - ByteBuf *wanted = BB_new_bytes("foobar", 6); - ByteBuf *got = BB_new_bytes("foo", 3); - Blob *blob = Blob_new("bar", 3); + ByteBuf *bb = BB_new_bytes("foo", 3); - BB_Cat(got, blob); - TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Cat"); + { + Blob *blob = Blob_new("bar", 3); + BB_Cat(bb, blob); + TEST_TRUE(runner, BB_Equals_Bytes(bb, "foobar", 6), "Cat"); + DECREF(blob); + } - BB_Mimic_Bytes(wanted, "foobarbaz", 9); - BB_Cat_Bytes(got, "baz", 3); - TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Cat_Bytes"); + BB_Cat_Bytes(bb, "baz", 3); + TEST_TRUE(runner, BB_Equals_Bytes(bb, "foobarbaz", 9), "Cat_Bytes"); - DECREF(blob); - DECREF(got); - DECREF(wanted); + DECREF(bb); } static void @@ -169,12 +151,11 @@ test_Utf8_To_String(TestBatchRunner *runner) { void TestBB_Run_IMP(TestByteBuf *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 22); + TestBatchRunner_Plan(runner, (TestBatch*)self, 17); test_Equals(runner); test_Grow(runner); test_Clone(runner); test_Compare_To(runner); - test_Mimic(runner); test_Utf8_To_String(runner); test_Cat(runner); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c8c942d3/runtime/go/clownfish/bytebuf_test.go ---------------------------------------------------------------------- diff --git a/runtime/go/clownfish/bytebuf_test.go b/runtime/go/clownfish/bytebuf_test.go index 66c9772..2cc2a27 100644 --- a/runtime/go/clownfish/bytebuf_test.go +++ b/runtime/go/clownfish/bytebuf_test.go @@ -49,17 +49,6 @@ func TestByteBufGetCapacity(t *testing.T) { } } -func TestByteBufMimic(t *testing.T) { - bb := NewByteBuf(0) - content := []byte("foo") - bb.cat(content) - other := NewByteBuf(0) - other.Mimic(bb) - if got := other.yieldBlob(); !reflect.DeepEqual(got, content) { - t.Errorf("Expected %v, got %v", content, got) - } -} - func TestByteBufEquals(t *testing.T) { bb := NewByteBuf(0) other := NewByteBuf(0) http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c8c942d3/runtime/perl/t/binding/022-bytebuf.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/binding/022-bytebuf.t b/runtime/perl/t/binding/022-bytebuf.t index 09edae8..b6bd61e 100644 --- a/runtime/perl/t/binding/022-bytebuf.t +++ b/runtime/perl/t/binding/022-bytebuf.t @@ -17,7 +17,7 @@ use strict; use warnings; use lib 'buildlib'; -use Test::More tests => 11; +use Test::More tests => 10; use Clownfish; my $buf = Clownfish::ByteBuf->new('abc'); @@ -36,9 +36,6 @@ ok( $buf->equals($buf), 'equals true'); ok( !$buf->equals($other), 'equals false'); ok( $buf->compare_to($other) < 0, 'compare_to'); -$buf->mimic($other); -ok( $buf->equals($other), 'mimic' ); - $buf = $other->clone_raw; isa_ok( $buf, 'Clownfish::ByteBuf', 'clone' ); ok( $buf->equals($other), 'equals after clone' );