You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/07/14 16:05:53 UTC

[3/6] lucy-clownfish git commit: Fix Vec_Insert_All

Fix Vec_Insert_All


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

Branch: refs/heads/master
Commit: 5153beff28d3066da42bdee782875e75168a508c
Parents: cd34607
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Jul 14 13:24:16 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Jul 14 13:54:13 2015 +0200

----------------------------------------------------------------------
 runtime/core/Clownfish/Test/TestVector.c | 46 ++++++++++++++++++++++++++-
 runtime/core/Clownfish/Vector.c          |  7 ++--
 2 files changed, 49 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5153beff/runtime/core/Clownfish/Test/TestVector.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestVector.c b/runtime/core/Clownfish/Test/TestVector.c
index aad8369..1a72768 100644
--- a/runtime/core/Clownfish/Test/TestVector.c
+++ b/runtime/core/Clownfish/Test/TestVector.c
@@ -179,6 +179,49 @@ test_Push_Pop_Insert(TestBatchRunner *runner) {
 }
 
 static void
+test_Insert_All(TestBatchRunner *runner) {
+    size_t i;
+
+    {
+        Vector *dst    = Vec_new(20);
+        Vector *src    = Vec_new(10);
+        Vector *wanted = Vec_new(30);
+
+        for (i = 0; i < 10; i++) { Vec_Push(dst, (Obj*)Int_new(i)); }
+        for (i = 0; i < 10; i++) { Vec_Push(dst, (Obj*)Int_new(i + 20)); }
+        for (i = 0; i < 10; i++) { Vec_Push(src, (Obj*)Int_new(i + 10)); }
+        for (i = 0; i < 30; i++) { Vec_Push(wanted, (Obj*)Int_new(i)); }
+
+        Vec_Insert_All(dst, 10, src);
+        TEST_TRUE(runner, Vec_Equals(dst, (Obj*)wanted), "Insert_All between");
+
+        DECREF(wanted);
+        DECREF(src);
+        DECREF(dst);
+    }
+
+    {
+        Vector *dst    = Vec_new(10);
+        Vector *src    = Vec_new(10);
+        Vector *wanted = Vec_new(30);
+
+        for (i = 0; i < 10; i++) { Vec_Push(dst, (Obj*)Int_new(i)); }
+        for (i = 0; i < 10; i++) { Vec_Push(src, (Obj*)Int_new(i + 20)); }
+        for (i = 0; i < 10; i++) { Vec_Push(wanted, (Obj*)Int_new(i)); }
+        for (i = 0; i < 10; i++) {
+            Vec_Store(wanted, i + 20, (Obj*)Int_new(i + 20));
+        }
+
+        Vec_Insert_All(dst, 20, src);
+        TEST_TRUE(runner, Vec_Equals(dst, (Obj*)wanted), "Insert_All after");
+
+        DECREF(wanted);
+        DECREF(src);
+        DECREF(dst);
+    }
+}
+
+static void
 test_Delete(TestBatchRunner *runner) {
     Vector *wanted = Vec_new(5);
     Vector *got    = Vec_new(5);
@@ -474,10 +517,11 @@ test_Grow(TestBatchRunner *runner) {
 
 void
 TestVector_Run_IMP(TestVector *self, TestBatchRunner *runner) {
-    TestBatchRunner_Plan(runner, (TestBatch*)self, 59);
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 61);
     test_Equals(runner);
     test_Store_Fetch(runner);
     test_Push_Pop_Insert(runner);
+    test_Insert_All(runner);
     test_Delete(runner);
     test_Resize(runner);
     test_Excise(runner);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5153beff/runtime/core/Clownfish/Vector.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Vector.c b/runtime/core/Clownfish/Vector.c
index 7f87fa1..2973e5b 100644
--- a/runtime/core/Clownfish/Vector.c
+++ b/runtime/core/Clownfish/Vector.c
@@ -127,19 +127,20 @@ Vec_Insert_IMP(Vector *self, size_t tick, Obj *elem) {
 
 void
 Vec_Insert_All_IMP(Vector *self, size_t tick, Vector *other) {
-    SI_add_grow_and_oversize(self, tick, other->size);
-
     if (tick < self->size) {
+        SI_add_grow_and_oversize(self, self->size, other->size);
         memmove(self->elems + tick + other->size, self->elems + tick,
                 (self->size - tick) * sizeof(Obj*));
+        self->size += other->size;
     }
     else {
+        SI_add_grow_and_oversize(self, tick, other->size);
         memset(self->elems + self->size, 0,
                (tick - self->size) * sizeof(Obj*));
+        self->size = tick + other->size;
     }
 
     SI_copy_and_incref(self->elems + tick, other->elems, other->size);
-    self->size = tick + other->size;
 }
 
 Obj*