Commit 352b3b98 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #39 from undingen/improve_collector

TraceStack: when visiting a range preallocate the elements.
parents b5131851 ca1266aa
......@@ -55,6 +55,7 @@ void TraceStackGCVisitor::visit(void* p) {
}
void TraceStackGCVisitor::visitRange(void** start, void** end) {
stack->reserve(end-start);
while (start < end) {
_visit(*start);
start++;
......
......@@ -59,6 +59,10 @@ class TraceStack {
return v.size();
}
void reserve(int num) {
v.reserve(num + v.size());
}
void* pop() {
if (v.size()) {
void* r = v.back();
......
......@@ -80,9 +80,7 @@ extern "C" void hcBoxGCHandler(GCVisitor *v, void* p) {
HCBox::AttrList *attr_list = b->attr_list;
assert(attr_list);
v->visit(attr_list);
for (int i = 0; i < nattrs; i++) {
v->visit(attr_list->attrs[i]);
}
v->visitRange((void**)&attr_list->attrs[0], (void**)&attr_list->attrs[nattrs]);
}
}
......@@ -127,8 +125,8 @@ extern "C" void tupleGCHandler(GCVisitor *v, void* p) {
BoxedTuple *t = (BoxedTuple*)p;
int size = t->elts.size();
for (int i = 0; i < size; i++) {
v->visit(t->elts[i]);
if (size) {
v->visitRange((void**)&t->elts[0], (void**)&t->elts[size]);
}
}
......
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