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