Commit bc3e118d authored by Boxiang Sun's avatar Boxiang Sun
parent bd39c49a
...@@ -131,15 +131,15 @@ const int BoxedList::INITIAL_CAPACITY = 8; ...@@ -131,15 +131,15 @@ const int BoxedList::INITIAL_CAPACITY = 8;
// TODO the inliner doesn't want to inline these; is there any point to having them in the inline section? // TODO the inliner doesn't want to inline these; is there any point to having them in the inline section?
void BoxedList::shrink() { void BoxedList::shrink() {
// TODO more attention to the shrink condition to avoid frequent shrink and alloc // TODO more attention to the shrink condition to avoid frequent shrink and alloc
if (capacity > size * 3) { if (allocated > size * 3) {
int new_capacity = std::max(static_cast<int64_t>(INITIAL_CAPACITY), capacity / 2); int new_allocated = std::max(static_cast<int64_t>(INITIAL_CAPACITY), allocated / 2);
if (size > 0) { if (size > 0) {
elts = GCdArray::grow(elts, new_capacity); elts = GCdArray::grow(elts, new_allocated);
capacity = new_capacity; allocated = new_allocated;
} else if (size == 0) { } else if (size == 0) {
delete elts; delete elts;
elts = NULL; elts = NULL;
capacity = 0; allocated = 0;
} }
} }
} }
...@@ -149,14 +149,14 @@ extern "C" void listAppendArrayInternal(Box* s, Box** v, int nelts) { ...@@ -149,14 +149,14 @@ extern "C" void listAppendArrayInternal(Box* s, Box** v, int nelts) {
assert(PyList_Check(s)); assert(PyList_Check(s));
BoxedList* self = static_cast<BoxedList*>(s); BoxedList* self = static_cast<BoxedList*>(s);
assert(self->size <= self->capacity); assert(self->size <= self->allocated);
self->ensure(nelts); self->ensure(nelts);
for (int i = 0; i < nelts; i++) { for (int i = 0; i < nelts; i++) {
Py_INCREF(v[i]); Py_INCREF(v[i]);
} }
assert(self->size <= self->capacity); assert(self->size <= self->allocated);
memcpy(&self->elts->elts[self->size], &v[0], nelts * sizeof(Box*)); memcpy(&self->elts->elts[self->size], &v[0], nelts * sizeof(Box*));
self->size += nelts; self->size += nelts;
......
...@@ -22,23 +22,23 @@ namespace pyston { ...@@ -22,23 +22,23 @@ namespace pyston {
// TODO the inliner doesn't want to inline these; is there any point to having them in the inline section? // TODO the inliner doesn't want to inline these; is there any point to having them in the inline section?
inline void BoxedList::grow(int min_free) { inline void BoxedList::grow(int min_free) {
if (capacity == 0) { if (allocated == 0) {
const int INITIAL_CAPACITY = 8; const int INITIAL_CAPACITY = 8;
int initial = std::max(INITIAL_CAPACITY, min_free); int initial = std::max(INITIAL_CAPACITY, min_free);
elts = new (initial) GCdArray(); elts = new (initial) GCdArray();
capacity = initial; allocated = initial;
} else { } else {
int new_capacity = std::max(capacity * 2, size + min_free); int new_allocated = std::max(allocated * 2, size + min_free);
elts = GCdArray::grow(elts, new_capacity); elts = GCdArray::grow(elts, new_allocated);
capacity = new_capacity; allocated = new_allocated;
} }
} }
inline void BoxedList::ensure(int min_free) { inline void BoxedList::ensure(int min_free) {
if (unlikely(size + min_free > capacity)) { if (unlikely(size + min_free > allocated)) {
grow(min_free); grow(min_free);
} }
assert(capacity >= size + min_free); assert(allocated >= size + min_free);
} }
// TODO the inliner doesn't want to inline these; is there any point to having them in the inline section? // TODO the inliner doesn't want to inline these; is there any point to having them in the inline section?
...@@ -48,10 +48,10 @@ extern "C" inline void listAppendInternalStolen(Box* s, Box* v) { ...@@ -48,10 +48,10 @@ extern "C" inline void listAppendInternalStolen(Box* s, Box* v) {
assert(PyList_Check(s)); assert(PyList_Check(s));
BoxedList* self = static_cast<BoxedList*>(s); BoxedList* self = static_cast<BoxedList*>(s);
assert(self->size <= self->capacity); assert(self->size <= self->allocated);
self->ensure(1); self->ensure(1);
assert(self->size < self->capacity); assert(self->size < self->allocated);
self->elts->elts[self->size] = v; self->elts->elts[self->size] = v;
self->size++; self->size++;
} }
......
...@@ -1426,7 +1426,7 @@ int BoxedList::clear(Box* _a) noexcept { ...@@ -1426,7 +1426,7 @@ int BoxedList::clear(Box* _a) noexcept {
this list, we make it empty first. */ this list, we make it empty first. */
i = Py_SIZE(a); i = Py_SIZE(a);
Py_SIZE(a) = 0; Py_SIZE(a) = 0;
a->capacity = 0; a->allocated = 0;
auto old_elts = a->elts; auto old_elts = a->elts;
a->elts = NULL; a->elts = NULL;
while (--i >= 0) { while (--i >= 0) {
......
...@@ -718,9 +718,9 @@ private: ...@@ -718,9 +718,9 @@ private:
public: public:
Py_ssize_t size; Py_ssize_t size;
GCdArray* elts; GCdArray* elts;
Py_ssize_t capacity; Py_ssize_t allocated;
BoxedList() __attribute__((visibility("default"))) : size(0), elts(NULL), capacity(0) {} BoxedList() __attribute__((visibility("default"))) : size(0), elts(NULL), allocated(0) {}
void ensure(int min_free); void ensure(int min_free);
void shrink(); void shrink();
...@@ -737,7 +737,7 @@ static_assert(sizeof(BoxedList) >= sizeof(PyListObject), ""); ...@@ -737,7 +737,7 @@ static_assert(sizeof(BoxedList) >= sizeof(PyListObject), "");
static_assert(offsetof(BoxedList, size) == offsetof(PyListObject, ob_size), ""); static_assert(offsetof(BoxedList, size) == offsetof(PyListObject, ob_size), "");
static_assert(offsetof(BoxedList, elts) == offsetof(PyListObject, ob_item), ""); static_assert(offsetof(BoxedList, elts) == offsetof(PyListObject, ob_item), "");
static_assert(offsetof(GCdArray, elts) == 0, ""); static_assert(offsetof(GCdArray, elts) == 0, "");
static_assert(offsetof(BoxedList, capacity) == offsetof(PyListObject, allocated), ""); static_assert(offsetof(BoxedList, allocated) == offsetof(PyListObject, allocated), "");
#define PyTuple_MAXSAVESIZE 20 /* Largest tuple to save on free list */ #define PyTuple_MAXSAVESIZE 20 /* Largest tuple to save on free list */
#define PyTuple_MAXFREELIST 2000 /* Maximum number of tuples of each size to save */ #define PyTuple_MAXFREELIST 2000 /* Maximum number of tuples of each size to save */
......
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