Commit 232557a4 authored by Marius Wachtler's avatar Marius Wachtler Committed by GitHub

Merge pull request #1324 from undingen/small_impr

use PyObject_Malloc in pyston::DenseMap, smaller ICInvalidator, reduce malloc calls
parents e4a492a6 f6009c25
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
#include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm/Support/PointerLikeTypeTraits.h"
#include "llvm/Support/type_traits.h" #include "llvm/Support/type_traits.h"
// Pyston change: use the python allocator
#include "Python.h"
namespace pyston { namespace pyston {
// This should only take effect for this header file: // This should only take effect for this header file:
...@@ -721,6 +724,10 @@ private: ...@@ -721,6 +724,10 @@ private:
Buckets = static_cast<BucketT*>(operator new(sizeof(BucketT) * NumBuckets)); Buckets = static_cast<BucketT*>(operator new(sizeof(BucketT) * NumBuckets));
return true; return true;
} }
// Pyston change: use the python allocator
static void* operator new(size_t count) { return PyObject_Malloc(count); }
static void operator delete(void* p) { PyObject_Free(p); }
}; };
template <typename KeyT, typename ValueT, unsigned InlineBuckets = 4, template <typename KeyT, typename ValueT, unsigned InlineBuckets = 4,
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/iterator_range.h" #include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "Python.h" #include "Python.h"
#include "core/common.h" #include "core/common.h"
...@@ -288,7 +289,7 @@ struct ParamReceiveSpec { ...@@ -288,7 +289,7 @@ struct ParamReceiveSpec {
class ICInvalidator { class ICInvalidator {
private: private:
int64_t cur_version; int64_t cur_version;
std::unordered_set<ICSlotInfo*> dependents; llvm::SmallPtrSet<ICSlotInfo*, 2> dependents;
public: public:
ICInvalidator() : cur_version(0) {} ICInvalidator() : cur_version(0) {}
......
...@@ -342,17 +342,17 @@ extern "C" PyObject* PyInt_FromString(const char* s, char** pend, int base) noex ...@@ -342,17 +342,17 @@ extern "C" PyObject* PyInt_FromString(const char* s, char** pend, int base) noex
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
extern "C" PyObject* PyInt_FromUnicode(Py_UNICODE* s, Py_ssize_t length, int base) noexcept { extern "C" PyObject* PyInt_FromUnicode(Py_UNICODE* s, Py_ssize_t length, int base) noexcept {
PyObject* result; PyObject* result;
char* buffer = (char*)malloc(length + 1); char* buffer = (char*)PyMem_MALLOC(length + 1);
if (buffer == NULL) if (buffer == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();
if (PyUnicode_EncodeDecimal(s, length, buffer, NULL)) { if (PyUnicode_EncodeDecimal(s, length, buffer, NULL)) {
free(buffer); PyMem_FREE(buffer);
return NULL; return NULL;
} }
result = PyInt_FromString(buffer, NULL, base); result = PyInt_FromString(buffer, NULL, base);
free(buffer); PyMem_FREE(buffer);
return result; return result;
} }
#endif #endif
......
...@@ -515,9 +515,6 @@ Box* setUnion(BoxedSet* self, BoxedTuple* args) { ...@@ -515,9 +515,6 @@ Box* setUnion(BoxedSet* self, BoxedTuple* args) {
BoxedSet* rtn = makeNewSet(self->cls, self); BoxedSet* rtn = makeNewSet(self->cls, self);
AUTO_DECREF(rtn); AUTO_DECREF(rtn);
for (auto&& p : self->s)
_setAdd(rtn, p);
for (auto container : args->pyElements()) { for (auto container : args->pyElements()) {
AUTO_DECREF(container); AUTO_DECREF(container);
for (auto elt : container->pyElements()) { for (auto elt : container->pyElements()) {
......
...@@ -265,7 +265,7 @@ Box* tupleRepr(Box* _t) { ...@@ -265,7 +265,7 @@ Box* tupleRepr(Box* _t) {
BoxedTuple* t = (BoxedTuple*)_t; BoxedTuple* t = (BoxedTuple*)_t;
int n; int n;
std::vector<char> chars; llvm::SmallVector<char, 128> chars;
int status = Py_ReprEnter((PyObject*)t); int status = Py_ReprEnter((PyObject*)t);
n = t->size(); n = t->size();
if (n == 0) { if (n == 0) {
...@@ -427,7 +427,7 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) { ...@@ -427,7 +427,7 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
return r; return r;
} }
std::vector<Box*> elts; llvm::SmallVector<Box*, 16> elts;
try { try {
for (auto e : elements->pyElements()) for (auto e : elements->pyElements())
elts.push_back(e); elts.push_back(e);
...@@ -437,10 +437,16 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) { ...@@ -437,10 +437,16 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
throw e; throw e;
} }
auto rtn = BoxedTuple::create(elts.size(), cls); if (elts.empty()) {
memcpy(&rtn->elts[0], &elts[0], elts.size() * sizeof(Box*)); if (cls == tuple_cls)
return incref(EmptyTuple);
return BoxedTuple::create(0, cls);
} else {
auto rtn = BoxedTuple::create(elts.size(), cls);
memcpy(&rtn->elts[0], &elts[0], elts.size() * sizeof(Box*));
return rtn;
}
return rtn;
} else { } else {
if (cls == tuple_cls) if (cls == tuple_cls)
return incref(EmptyTuple); return incref(EmptyTuple);
......
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