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