Reduce code size of Vec_Insert methods
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/c91a9e44 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/c91a9e44 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/c91a9e44 Branch: refs/heads/master Commit: c91a9e44747847a2b58978efb565b1ce04c72696 Parents: 5153bef Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Tue Jul 14 13:53:12 2015 +0200 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Tue Jul 14 13:54:13 2015 +0200 ---------------------------------------------------------------------- runtime/core/Clownfish/Vector.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c91a9e44/runtime/core/Clownfish/Vector.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Vector.c b/runtime/core/Clownfish/Vector.c index 2973e5b..8dbf3cc 100644 --- a/runtime/core/Clownfish/Vector.c +++ b/runtime/core/Clownfish/Vector.c @@ -109,38 +109,38 @@ Vec_Pop_IMP(Vector *self) { void Vec_Insert_IMP(Vector *self, size_t tick, Obj *elem) { + size_t max_tick = tick > self->size ? tick : self->size; + SI_add_grow_and_oversize(self, max_tick, 1); + if (tick < self->size) { - SI_add_grow_and_oversize(self, self->size, 1); memmove(self->elems + tick + 1, self->elems + tick, (self->size - tick) * sizeof(Obj*)); - self->size++; } else { - SI_add_grow_and_oversize(self, tick, 1); memset(self->elems + self->size, 0, (tick - self->size) * sizeof(Obj*)); - self->size = tick + 1; } self->elems[tick] = elem; + self->size = max_tick + 1; } void Vec_Insert_All_IMP(Vector *self, size_t tick, Vector *other) { + size_t max_tick = tick > self->size ? tick : self->size; + SI_add_grow_and_oversize(self, max_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 = max_tick + other->size; } Obj*