Commit b4fabb63 authored by Marius Wachtler's avatar Marius Wachtler

add listAppendArrayInternal which appends an array of elements to a list

parent 87d1620d
......@@ -108,6 +108,7 @@ Box* range1(Box* end) {
BoxedList *rtn = new BoxedList();
i64 iend = static_cast<BoxedInt*>(end)->n;
rtn->ensure(iend);
for (i64 i = 0; i < iend; i++) {
Box *bi = boxInt(i);
listAppendInternal(rtn, bi);
......@@ -122,10 +123,10 @@ Box* range2(Box* start, Box* end) {
BoxedList *rtn = new BoxedList();
i64 istart = static_cast<BoxedInt*>(start)->n;
i64 iend = static_cast<BoxedInt*>(end)->n;
if ((iend-istart) > 0)
rtn->ensure(iend-istart);
for (i64 i = istart; i < iend; i++) {
Box *bi = boxInt(i);
listAppendInternal(rtn, bi);
listAppendInternal(rtn, boxInt(i));
}
return rtn;
}
......
......@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstring>
#include "runtime/list.h"
#include "runtime/gc_runtime.h"
......@@ -80,6 +82,20 @@ extern "C" void listAppendInternal(Box* s, Box* v) {
self->size++;
}
extern "C" void listAppendArrayInternal(Box* s, Box** v, int nelts) {
assert(s->cls == list_cls);
BoxedList* self = static_cast<BoxedList*>(s);
assert(self->size <= self->capacity);
self->ensure(nelts);
assert(self->size <= self->capacity);
memcpy(&self->elts->elts[self->size], &v[0], nelts*sizeof(Box*));
self->size += nelts;
}
// TODO the inliner doesn't want to inline these; is there any point to having them in the inline section?
extern "C" Box* listAppend(Box* s, Box* v) {
assert(s->cls == list_cls);
......
......@@ -224,11 +224,17 @@ Box* listMul(BoxedList* self, Box* rhs) {
int s = self->size;
BoxedList* rtn = new BoxedList();
for (int i = 0; i < n; i++) {
for (int j = 0; j < s; j++) {
listAppendInternal(rtn, self->elts->elts[j]);
rtn->ensure(n*s);
if (s == 1) {
for (int i = 0; i < n; i++) {
listAppendInternal(rtn, self->elts->elts[0]);
}
} else {
for (int i = 0; i < n; i++) {
listAppendArrayInternal(rtn, &self->elts->elts[0], s);
}
}
return rtn;
}
......
......@@ -75,6 +75,7 @@ extern "C" Box* boxStringPtr(const std::string *s);
Box* boxString(const std::string &s);
extern "C" BoxedString* boxStrConstant(const char* chars);
extern "C" void listAppendInternal(Box* self, Box* v);
extern "C" void listAppendArrayInternal(Box* self, Box** v, int nelts);
extern "C" Box* boxCLFunction(CLFunction *f);
extern "C" CLFunction* unboxCLFunction(Box* b);
extern "C" Box* createClass(std::string *name, BoxedModule *parent_module);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment