Commit a7653f03 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #1187 from kmod/perf9

Extract the logic from DEFAULT_CLASS_SIMPLE
parents 9c925c4e 4f83635c
This diff is collapsed.
......@@ -26,7 +26,7 @@ BoxedDictIterator::BoxedDictIterator(BoxedDict* d) : d(d), it(d->d.begin()), itE
Box* dict_iter(Box* s) noexcept {
assert(PyDict_Check(s));
BoxedDict* self = static_cast<BoxedDict*>(s);
return new (&PyDictIterKey_Type) BoxedDictIterator(self);
return new (&PyDictIterKey_Type, FAST_GC) BoxedDictIterator(self);
}
Box* dictIterKeys(Box* s) {
......@@ -36,13 +36,13 @@ Box* dictIterKeys(Box* s) {
Box* dictIterValues(Box* s) {
assert(PyDict_Check(s));
BoxedDict* self = static_cast<BoxedDict*>(s);
return new (&PyDictIterValue_Type) BoxedDictIterator(self);
return new (&PyDictIterValue_Type, FAST_GC) BoxedDictIterator(self);
}
Box* dictIterItems(Box* s) {
assert(PyDict_Check(s));
BoxedDict* self = static_cast<BoxedDict*>(s);
return new (&PyDictIterItem_Type) BoxedDictIterator(self);
return new (&PyDictIterItem_Type, FAST_GC) BoxedDictIterator(self);
}
Box* dictIterIter(Box* s) {
......
......@@ -33,7 +33,7 @@ Box* listIterIter(Box* s) {
Box* listIter(Box* s) noexcept {
assert(PyList_Check(s));
BoxedList* self = static_cast<BoxedList*>(s);
return new BoxedListIterator(self, 0);
return new (list_iterator_cls, FAST_GC) BoxedListIterator(self, 0);
}
Box* listiterHasnext(Box* s) {
......@@ -89,7 +89,7 @@ Box* listiter_next(Box* s) noexcept {
Box* listReversed(Box* s) {
assert(PyList_Check(s));
BoxedList* self = static_cast<BoxedList*>(s);
return new (list_reverse_iterator_cls) BoxedListIterator(self, self->size - 1);
return new (list_reverse_iterator_cls, FAST_GC) BoxedListIterator(self, self->size - 1);
}
Box* listreviterHasnext(Box* s) {
......
......@@ -28,8 +28,6 @@ public:
int pos;
BoxedListIterator(BoxedList* l, int start);
DEFAULT_CLASS(list_iterator_cls);
static void dealloc(BoxedListIterator* o) noexcept {
PyObject_GC_UnTrack(o);
Py_XDECREF(o->l);
......
......@@ -33,7 +33,7 @@ public:
BoxedLong() __attribute__((visibility("default"))) {}
DEFAULT_CLASS(long_cls);
DEFAULT_CLASS_SIMPLE(long_cls, false);
};
extern "C" Box* createLong(llvm::StringRef s);
......
......@@ -2217,7 +2217,7 @@ public:
b = NULL;
}
DEFAULT_CLASS(attrwrapper_cls);
DEFAULT_CLASS_SIMPLE(attrwrapper_cls, true);
BORROWED(Box*) getUnderlying() {
......
......@@ -281,6 +281,42 @@ protected:
friend void setupThread();
};
template <bool is_gc> void* Box::newFast(size_t size, BoxedClass* cls) {
ALLOC_STATS(cls);
assert(cls->tp_alloc == PyType_GenericAlloc);
assert(cls->tp_itemsize == 0);
assert(cls->tp_basicsize == size);
assert(cls->is_pyston_class);
assert(cls->attrs_offset == 0);
assert(is_gc == PyType_IS_GC(cls));
bool is_heaptype = false;
assert(is_heaptype == (bool)(cls->tp_flags & Py_TPFLAGS_HEAPTYPE));
/* Don't allocate classes through this -- we need to keep track of all class objects. */
assert(cls != type_cls);
/* note: we want to use size instead of tp_basicsize, since size is a compile-time constant */
void* mem;
if (is_gc)
mem = _PyObject_GC_Malloc(size);
else
mem = PyObject_MALLOC(size);
assert(mem);
Box* rtn = static_cast<Box*>(mem);
if (is_heaptype)
Py_INCREF(cls);
PyObject_INIT(rtn, cls);
if (is_gc)
_PyObject_GC_TRACK(rtn);
return rtn;
/* TODO: there should be a way to not have to do this nested inlining by hand */
}
// Corresponds to PyHeapTypeObject. Very similar to BoxedClass, but allocates some extra space for
// structures that otherwise might get allocated statically. For instance, tp_as_number for builtin
// types will usually point to a `static PyNumberMethods` object, but for a heap-allocated class it
......
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