Commit aba975d1 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #717 from kmod/attr_perf

reenable PyList macros
parents 4385b6bc f9326e16
...@@ -20,8 +20,6 @@ returned item's reference count. ...@@ -20,8 +20,6 @@ returned item's reference count.
extern "C" { extern "C" {
#endif #endif
// Pyston change: comment this out since this is not the format we're using
#if 0
typedef struct { typedef struct {
PyObject_VAR_HEAD PyObject_VAR_HEAD
/* Vector of pointers to list elements. list[0] is ob_item[0], etc. */ /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
...@@ -40,9 +38,6 @@ typedef struct { ...@@ -40,9 +38,6 @@ typedef struct {
*/ */
Py_ssize_t allocated; Py_ssize_t allocated;
} PyListObject; } PyListObject;
#endif
struct _PyListObject;
typedef struct _PyListObject PyListObject;
// Pyston change: this is no longer a static object // Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) list_cls; PyAPI_DATA(PyTypeObject*) list_cls;
...@@ -69,13 +64,9 @@ PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *) PYSTON_NOEXCEP ...@@ -69,13 +64,9 @@ PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *) PYSTON_NOEXCEP
PyAPI_FUNC(PyObject **) PyList_Items(PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject **) PyList_Items(PyObject *) PYSTON_NOEXCEPT;
/* Macro, trading safety for speed */ /* Macro, trading safety for speed */
// Pyston changes: these aren't direct macros any more [they potentially could be though] #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
#define PyList_GET_ITEM(op, i) PyList_GetItem((PyObject*)(op), (i)) #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
#define PyList_SET_ITEM(op, i, v) PyList_SetItem((PyObject*)(op), (i), (v)) #define PyList_GET_SIZE(op) Py_SIZE(op)
#define PyList_GET_SIZE(op) PyList_Size((PyObject*)(op))
//#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
//#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
//#define PyList_GET_SIZE(op) Py_SIZE(op)
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -115,8 +115,6 @@ void BoxedList::shrink() { ...@@ -115,8 +115,6 @@ void BoxedList::shrink() {
extern "C" void listAppendArrayInternal(Box* s, Box** v, int nelts) { extern "C" void listAppendArrayInternal(Box* s, Box** v, int nelts) {
// Lock must be held!
assert(isSubclass(s->cls, list_cls)); assert(isSubclass(s->cls, list_cls));
BoxedList* self = static_cast<BoxedList*>(s); BoxedList* self = static_cast<BoxedList*>(s);
...@@ -134,8 +132,6 @@ extern "C" Box* listAppend(Box* s, Box* v) { ...@@ -134,8 +132,6 @@ extern "C" Box* listAppend(Box* s, Box* v) {
assert(isSubclass(s->cls, list_cls)); assert(isSubclass(s->cls, list_cls));
BoxedList* self = static_cast<BoxedList*>(s); BoxedList* self = static_cast<BoxedList*>(s);
LOCK_REGION(self->lock.asWrite());
listAppendInternal(self, v); listAppendInternal(self, v);
return None; return None;
......
...@@ -63,8 +63,6 @@ extern "C" PyObject* PyList_AsTuple(PyObject* v) noexcept { ...@@ -63,8 +63,6 @@ extern "C" PyObject* PyList_AsTuple(PyObject* v) noexcept {
} }
extern "C" Box* listRepr(BoxedList* self) { extern "C" Box* listRepr(BoxedList* self) {
LOCK_REGION(self->lock.asRead());
// TODO highly inefficient with all the string copying // TODO highly inefficient with all the string copying
std::string O(""); std::string O("");
...@@ -89,8 +87,6 @@ extern "C" Box* listNonzero(BoxedList* self) { ...@@ -89,8 +87,6 @@ extern "C" Box* listNonzero(BoxedList* self) {
} }
extern "C" Box* listPop(BoxedList* self, Box* idx) { extern "C" Box* listPop(BoxedList* self, Box* idx) {
LOCK_REGION(self->lock.asWrite());
if (idx == None) { if (idx == None) {
if (self->size == 0) { if (self->size == 0) {
raiseExcHelper(IndexError, "pop from empty list"); raiseExcHelper(IndexError, "pop from empty list");
...@@ -190,8 +186,6 @@ static Box* list_slice(Box* o, Py_ssize_t ilow, Py_ssize_t ihigh) noexcept { ...@@ -190,8 +186,6 @@ static Box* list_slice(Box* o, Py_ssize_t ilow, Py_ssize_t ihigh) noexcept {
} }
extern "C" Box* listGetitemUnboxed(BoxedList* self, int64_t n) { extern "C" Box* listGetitemUnboxed(BoxedList* self, int64_t n) {
LOCK_REGION(self->lock.asRead());
assert(isSubclass(self->cls, list_cls)); assert(isSubclass(self->cls, list_cls));
if (n < 0) if (n < 0)
n = self->size + n; n = self->size + n;
...@@ -219,8 +213,6 @@ extern "C" PyObject* PyList_GetItem(PyObject* op, Py_ssize_t i) noexcept { ...@@ -219,8 +213,6 @@ extern "C" PyObject* PyList_GetItem(PyObject* op, Py_ssize_t i) noexcept {
} }
extern "C" Box* listGetitemSlice(BoxedList* self, BoxedSlice* slice) { extern "C" Box* listGetitemSlice(BoxedList* self, BoxedSlice* slice) {
LOCK_REGION(self->lock.asRead());
assert(isSubclass(self->cls, list_cls)); assert(isSubclass(self->cls, list_cls));
assert(slice->cls == slice_cls); assert(slice->cls == slice_cls);
i64 start, stop, step, length; i64 start, stop, step, length;
...@@ -254,8 +246,6 @@ static void _listSetitem(BoxedList* self, int64_t n, Box* v) { ...@@ -254,8 +246,6 @@ static void _listSetitem(BoxedList* self, int64_t n, Box* v) {
} }
extern "C" Box* listSetitemUnboxed(BoxedList* self, int64_t n, Box* v) { extern "C" Box* listSetitemUnboxed(BoxedList* self, int64_t n, Box* v) {
// I think r lock is ok here, since we don't change the list structure:
LOCK_REGION(self->lock.asRead());
assert(isSubclass(self->cls, list_cls)); assert(isSubclass(self->cls, list_cls));
_listSetitem(self, n, v); _listSetitem(self, n, v);
return None; return None;
...@@ -267,12 +257,22 @@ extern "C" Box* listSetitemInt(BoxedList* self, BoxedInt* slice, Box* v) { ...@@ -267,12 +257,22 @@ extern "C" Box* listSetitemInt(BoxedList* self, BoxedInt* slice, Box* v) {
} }
extern "C" int PyList_SetItem(PyObject* op, Py_ssize_t i, PyObject* newitem) noexcept { extern "C" int PyList_SetItem(PyObject* op, Py_ssize_t i, PyObject* newitem) noexcept {
assert(isSubclass(op->cls, list_cls)); PyObject* olditem;
try { PyObject** p;
listSetitemUnboxed(static_cast<BoxedList*>(op), i, newitem); if (!PyList_Check(op)) {
} catch (ExcInfo e) { Py_XDECREF(newitem);
abort(); PyErr_BadInternalCall();
return -1;
}
if (i < 0 || i >= Py_SIZE(op)) {
Py_XDECREF(newitem);
PyErr_SetString(PyExc_IndexError, "list assignment index out of range");
return -1;
} }
p = ((PyListObject*)op)->ob_item + i;
olditem = *p;
*p = newitem;
Py_XDECREF(olditem);
return 0; return 0;
} }
...@@ -420,8 +420,6 @@ int list_ass_ext_slice(BoxedList* self, PyObject* item, PyObject* value) { ...@@ -420,8 +420,6 @@ int list_ass_ext_slice(BoxedList* self, PyObject* item, PyObject* value) {
} }
extern "C" Box* listSetitemSlice(BoxedList* self, BoxedSlice* slice, Box* v) { extern "C" Box* listSetitemSlice(BoxedList* self, BoxedSlice* slice, Box* v) {
LOCK_REGION(self->lock.asWrite());
assert(isSubclass(self->cls, list_cls)); assert(isSubclass(self->cls, list_cls));
assert(slice->cls == slice_cls); assert(slice->cls == slice_cls);
...@@ -516,8 +514,6 @@ extern "C" Box* listSetitem(BoxedList* self, Box* slice, Box* v) { ...@@ -516,8 +514,6 @@ extern "C" Box* listSetitem(BoxedList* self, Box* slice, Box* v) {
} }
extern "C" Box* listDelitemInt(BoxedList* self, BoxedInt* slice) { extern "C" Box* listDelitemInt(BoxedList* self, BoxedInt* slice) {
LOCK_REGION(self->lock.asWrite());
int64_t n = slice->n; int64_t n = slice->n;
if (n < 0) if (n < 0)
n = self->size + n; n = self->size + n;
...@@ -535,8 +531,6 @@ extern "C" Box* listDelitemSlice(BoxedList* self, BoxedSlice* slice) { ...@@ -535,8 +531,6 @@ extern "C" Box* listDelitemSlice(BoxedList* self, BoxedSlice* slice) {
} }
extern "C" Box* listDelitem(BoxedList* self, Box* slice) { extern "C" Box* listDelitem(BoxedList* self, Box* slice) {
LOCK_REGION(self->lock.asWrite());
Box* rtn; Box* rtn;
if (PyIndex_Check(slice)) { if (PyIndex_Check(slice)) {
Py_ssize_t i = PyNumber_AsSsize_t(slice, PyExc_IndexError); Py_ssize_t i = PyNumber_AsSsize_t(slice, PyExc_IndexError);
...@@ -557,8 +551,6 @@ extern "C" Box* listInsert(BoxedList* self, Box* idx, Box* v) { ...@@ -557,8 +551,6 @@ extern "C" Box* listInsert(BoxedList* self, Box* idx, Box* v) {
raiseExcHelper(TypeError, "an integer is required"); raiseExcHelper(TypeError, "an integer is required");
} }
LOCK_REGION(self->lock.asWrite());
int64_t n = static_cast<BoxedInt*>(idx)->n; int64_t n = static_cast<BoxedInt*>(idx)->n;
if (n < 0) if (n < 0)
n = self->size + n; n = self->size + n;
...@@ -603,8 +595,6 @@ Box* listMul(BoxedList* self, Box* rhs) { ...@@ -603,8 +595,6 @@ Box* listMul(BoxedList* self, Box* rhs) {
raiseExcHelper(TypeError, "can't multiply sequence by non-int of type '%s'", getTypeName(rhs)); raiseExcHelper(TypeError, "can't multiply sequence by non-int of type '%s'", getTypeName(rhs));
} }
LOCK_REGION(self->lock.asRead());
int n = static_cast<BoxedInt*>(rhs)->n; int n = static_cast<BoxedInt*>(rhs)->n;
int s = self->size; int s = self->size;
...@@ -624,8 +614,6 @@ Box* listMul(BoxedList* self, Box* rhs) { ...@@ -624,8 +614,6 @@ Box* listMul(BoxedList* self, Box* rhs) {
} }
Box* listIAdd(BoxedList* self, Box* _rhs) { Box* listIAdd(BoxedList* self, Box* _rhs) {
LOCK_REGION(self->lock.asWrite());
if (_rhs->cls == list_cls) { if (_rhs->cls == list_cls) {
// This branch is safe if self==rhs: // This branch is safe if self==rhs:
BoxedList* rhs = static_cast<BoxedList*>(_rhs); BoxedList* rhs = static_cast<BoxedList*>(_rhs);
...@@ -656,8 +644,6 @@ Box* listAdd(BoxedList* self, Box* _rhs) { ...@@ -656,8 +644,6 @@ Box* listAdd(BoxedList* self, Box* _rhs) {
raiseExcHelper(TypeError, "can only concatenate list (not \"%s\") to list", getTypeName(_rhs)); raiseExcHelper(TypeError, "can only concatenate list (not \"%s\") to list", getTypeName(_rhs));
} }
LOCK_REGION(self->lock.asRead());
BoxedList* rhs = static_cast<BoxedList*>(_rhs); BoxedList* rhs = static_cast<BoxedList*>(_rhs);
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
...@@ -673,8 +659,6 @@ Box* listAdd(BoxedList* self, Box* _rhs) { ...@@ -673,8 +659,6 @@ Box* listAdd(BoxedList* self, Box* _rhs) {
} }
Box* listReverse(BoxedList* self) { Box* listReverse(BoxedList* self) {
LOCK_REGION(self->lock.asWrite());
assert(isSubclass(self->cls, list_cls)); assert(isSubclass(self->cls, list_cls));
for (int i = 0, j = self->size - 1; i < j; i++, j--) { for (int i = 0, j = self->size - 1; i < j; i++, j--) {
Box* e = self->elts->elts[i]; Box* e = self->elts->elts[i];
...@@ -715,7 +699,6 @@ public: ...@@ -715,7 +699,6 @@ public:
}; };
void listSort(BoxedList* self, Box* cmp, Box* key, Box* reverse) { void listSort(BoxedList* self, Box* cmp, Box* key, Box* reverse) {
LOCK_REGION(self->lock.asWrite());
assert(isSubclass(self->cls, list_cls)); assert(isSubclass(self->cls, list_cls));
if (cmp == None) if (cmp == None)
...@@ -813,8 +796,6 @@ extern "C" Box* PyList_GetSlice(PyObject* a, Py_ssize_t ilow, Py_ssize_t ihigh) ...@@ -813,8 +796,6 @@ extern "C" Box* PyList_GetSlice(PyObject* a, Py_ssize_t ilow, Py_ssize_t ihigh)
} }
Box* listContains(BoxedList* self, Box* elt) { Box* listContains(BoxedList* self, Box* elt) {
LOCK_REGION(self->lock.asRead());
int size = self->size; int size = self->size;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Box* e = self->elts->elts[i]; Box* e = self->elts->elts[i];
...@@ -834,8 +815,6 @@ Box* listContains(BoxedList* self, Box* elt) { ...@@ -834,8 +815,6 @@ Box* listContains(BoxedList* self, Box* elt) {
} }
Box* listCount(BoxedList* self, Box* elt) { Box* listCount(BoxedList* self, Box* elt) {
LOCK_REGION(self->lock.asRead());
int size = self->size; int size = self->size;
int count = 0; int count = 0;
...@@ -853,8 +832,6 @@ Box* listCount(BoxedList* self, Box* elt) { ...@@ -853,8 +832,6 @@ Box* listCount(BoxedList* self, Box* elt) {
} }
Box* listIndex(BoxedList* self, Box* elt, BoxedInt* _start, Box** args) { Box* listIndex(BoxedList* self, Box* elt, BoxedInt* _start, Box** args) {
LOCK_REGION(self->lock.asRead());
BoxedInt* _stop = (BoxedInt*)args[0]; BoxedInt* _stop = (BoxedInt*)args[0];
RELEASE_ASSERT(!_start || _start->cls == int_cls, ""); RELEASE_ASSERT(!_start || _start->cls == int_cls, "");
RELEASE_ASSERT(!_stop || _stop->cls == int_cls, ""); RELEASE_ASSERT(!_stop || _stop->cls == int_cls, "");
...@@ -890,8 +867,6 @@ Box* listIndex(BoxedList* self, Box* elt, BoxedInt* _start, Box** args) { ...@@ -890,8 +867,6 @@ Box* listIndex(BoxedList* self, Box* elt, BoxedInt* _start, Box** args) {
} }
Box* listRemove(BoxedList* self, Box* elt) { Box* listRemove(BoxedList* self, Box* elt) {
LOCK_REGION(self->lock.asWrite());
assert(isSubclass(self->cls, list_cls)); assert(isSubclass(self->cls, list_cls));
for (int i = 0; i < self->size; i++) { for (int i = 0; i < self->size; i++) {
...@@ -1017,8 +992,6 @@ Box* listEq(BoxedList* self, Box* rhs) { ...@@ -1017,8 +992,6 @@ Box* listEq(BoxedList* self, Box* rhs) {
return NotImplemented; return NotImplemented;
} }
LOCK_REGION(self->lock.asRead());
return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::Eq); return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::Eq);
} }
...@@ -1027,8 +1000,6 @@ Box* listNe(BoxedList* self, Box* rhs) { ...@@ -1027,8 +1000,6 @@ Box* listNe(BoxedList* self, Box* rhs) {
return NotImplemented; return NotImplemented;
} }
LOCK_REGION(self->lock.asRead());
return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::NotEq); return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::NotEq);
} }
...@@ -1037,8 +1008,6 @@ Box* listLt(BoxedList* self, Box* rhs) { ...@@ -1037,8 +1008,6 @@ Box* listLt(BoxedList* self, Box* rhs) {
return NotImplemented; return NotImplemented;
} }
LOCK_REGION(self->lock.asRead());
return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::Lt); return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::Lt);
} }
...@@ -1047,8 +1016,6 @@ Box* listLe(BoxedList* self, Box* rhs) { ...@@ -1047,8 +1016,6 @@ Box* listLe(BoxedList* self, Box* rhs) {
return NotImplemented; return NotImplemented;
} }
LOCK_REGION(self->lock.asRead());
return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::LtE); return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::LtE);
} }
...@@ -1057,8 +1024,6 @@ Box* listGt(BoxedList* self, Box* rhs) { ...@@ -1057,8 +1024,6 @@ Box* listGt(BoxedList* self, Box* rhs) {
return NotImplemented; return NotImplemented;
} }
LOCK_REGION(self->lock.asRead());
return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::Gt); return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::Gt);
} }
...@@ -1067,8 +1032,6 @@ Box* listGe(BoxedList* self, Box* rhs) { ...@@ -1067,8 +1032,6 @@ Box* listGe(BoxedList* self, Box* rhs) {
return NotImplemented; return NotImplemented;
} }
LOCK_REGION(self->lock.asRead());
return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::GtE); return _listCmp(self, static_cast<BoxedList*>(rhs), AST_TYPE::GtE);
} }
......
...@@ -590,10 +590,9 @@ private: ...@@ -590,10 +590,9 @@ private:
void grow(int min_free); void grow(int min_free);
public: public:
int64_t size, capacity; Py_ssize_t size;
GCdArray* elts; GCdArray* elts;
Py_ssize_t capacity;
DS_DEFINE_MUTEX(lock);
BoxedList() __attribute__((visibility("default"))) : size(0), capacity(0) {} BoxedList() __attribute__((visibility("default"))) : size(0), capacity(0) {}
...@@ -603,6 +602,12 @@ public: ...@@ -603,6 +602,12 @@ public:
DEFAULT_CLASS_SIMPLE(list_cls); DEFAULT_CLASS_SIMPLE(list_cls);
}; };
static_assert(sizeof(BoxedList) <= sizeof(PyListObject), "");
static_assert(sizeof(BoxedList) >= sizeof(PyListObject), "");
static_assert(offsetof(BoxedList, size) == offsetof(PyListObject, ob_size), "");
static_assert(offsetof(BoxedList, elts) == offsetof(PyListObject, ob_item), "");
static_assert(offsetof(GCdArray, elts) == 0, "");
static_assert(offsetof(BoxedList, capacity) == offsetof(PyListObject, allocated), "");
class BoxedTuple : public BoxVar { class BoxedTuple : public BoxVar {
public: public:
......
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