Commit cab7c2dc authored by Kevin Modzelewski's avatar Kevin Modzelewski

Help our tuple-creation code hit the fast path more often

I think this only gets hit through explicit calls to tuple(),
but at one point it was crashing on this codepath which is
how I noticed it.
parent 6f24ad0f
...@@ -580,14 +580,26 @@ public: ...@@ -580,14 +580,26 @@ public:
} }
static BoxedTuple* create(std::initializer_list<Box*> members) { return new (members.size()) BoxedTuple(members); } static BoxedTuple* create(std::initializer_list<Box*> members) { return new (members.size()) BoxedTuple(members); }
static BoxedTuple* create(int64_t size, BoxedClass* cls) { return new (cls, size) BoxedTuple(size); } static BoxedTuple* create(int64_t size, BoxedClass* cls) {
if (cls == tuple_cls)
return new (size) BoxedTuple(size);
else
return new (cls, size) BoxedTuple(size);
}
static BoxedTuple* create(int64_t nelts, Box** elts, BoxedClass* cls) { static BoxedTuple* create(int64_t nelts, Box** elts, BoxedClass* cls) {
BoxedTuple* rtn = new (cls, nelts) BoxedTuple(nelts); BoxedTuple* rtn;
if (cls == tuple_cls)
rtn = new (nelts) BoxedTuple(nelts);
else
rtn = new (cls, nelts) BoxedTuple(nelts);
memmove(&rtn->elts[0], elts, sizeof(Box*) * nelts); memmove(&rtn->elts[0], elts, sizeof(Box*) * nelts);
return rtn; return rtn;
} }
static BoxedTuple* create(std::initializer_list<Box*> members, BoxedClass* cls) { static BoxedTuple* create(std::initializer_list<Box*> members, BoxedClass* cls) {
return new (cls, members.size()) BoxedTuple(members); if (cls == tuple_cls)
return new (members.size()) BoxedTuple(members);
else
return new (cls, members.size()) BoxedTuple(members);
} }
static int Resize(BoxedTuple** pt, size_t newsize) noexcept; static int Resize(BoxedTuple** pt, size_t newsize) noexcept;
...@@ -605,6 +617,7 @@ public: ...@@ -605,6 +617,7 @@ public:
assert(cls->tp_itemsize == sizeof(Box*)); assert(cls->tp_itemsize == sizeof(Box*));
return BoxVar::operator new(size, cls, nitems); return BoxVar::operator new(size, cls, nitems);
} }
void* operator new(size_t size, size_t nitems) __attribute__((visibility("default"))) { void* operator new(size_t size, size_t nitems) __attribute__((visibility("default"))) {
ALLOC_STATS_VAR(tuple_cls) ALLOC_STATS_VAR(tuple_cls)
......
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