Commit 1206cf29 authored by Marius Wachtler's avatar Marius Wachtler

microoptimizations

parent 85a1c69b
...@@ -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