Commit 4edaa1e2 authored by Chris Toshok's avatar Chris Toshok

ensure the lists are properly sized when we know what their size will be

parent 3431e9a2
...@@ -67,6 +67,7 @@ Box* dictCopy(BoxedDict* self) { ...@@ -67,6 +67,7 @@ Box* dictCopy(BoxedDict* self) {
Box* dictItems(BoxedDict* self) { Box* dictItems(BoxedDict* self) {
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
rtn->ensure(self->d.size());
for (const auto& p : self->d) { for (const auto& p : self->d) {
BoxedTuple::GCVector elts; BoxedTuple::GCVector elts;
elts.push_back(p.first); elts.push_back(p.first);
...@@ -80,6 +81,7 @@ Box* dictItems(BoxedDict* self) { ...@@ -80,6 +81,7 @@ Box* dictItems(BoxedDict* self) {
Box* dictValues(BoxedDict* self) { Box* dictValues(BoxedDict* self) {
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
rtn->ensure(self->d.size());
for (const auto& p : self->d) { for (const auto& p : self->d) {
listAppendInternal(rtn, p.second); listAppendInternal(rtn, p.second);
} }
...@@ -90,6 +92,7 @@ Box* dictKeys(BoxedDict* self) { ...@@ -90,6 +92,7 @@ Box* dictKeys(BoxedDict* self) {
RELEASE_ASSERT(isSubclass(self->cls, dict_cls), ""); RELEASE_ASSERT(isSubclass(self->cls, dict_cls), "");
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
rtn->ensure(self->d.size());
for (const auto& p : self->d) { for (const auto& p : self->d) {
listAppendInternal(rtn, p.first); listAppendInternal(rtn, p.first);
} }
......
...@@ -96,6 +96,7 @@ Box* BoxedTraceback::getLines(Box* b) { ...@@ -96,6 +96,7 @@ Box* BoxedTraceback::getLines(Box* b) {
if (!tb->py_lines) { if (!tb->py_lines) {
BoxedList* lines = new BoxedList(); BoxedList* lines = new BoxedList();
lines->ensure(tb->lines.size());
for (auto line : tb->lines) { for (auto line : tb->lines) {
auto l = new BoxedTuple({ boxString(line->file), boxString(line->func), boxInt(line->line) }); auto l = new BoxedTuple({ boxString(line->file), boxString(line->func), boxInt(line->line) });
listAppendInternal(lines, l); listAppendInternal(lines, l);
......
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