Commit dd7e9e2f authored by Kevin Modzelewski's avatar Kevin Modzelewski

A few small perf improvements

Plus a benchmark of the getattr() function.
I have some ideas on how to make this faster, but I don't
think it's that important at the moment.
parent 2e9a9e35
class C(object):
pass
def f():
g = getattr
c = C()
c.o = 1
for i in xrange(10000000):
g(c, "o")
f()
......@@ -249,6 +249,8 @@ extern "C" PyObject* PyDict_GetItem(PyObject* dict, PyObject* key) noexcept {
return d->getOrNull(key);
}
// XXX this would be easy to make much faster.
// This path doesn't exist in CPython; we have it to support extension modules that do
// something along the lines of PyDict_GetItem(PyModule_GetDict()):
try {
......@@ -304,6 +306,9 @@ extern "C" int PyDict_Next(PyObject* op, Py_ssize_t* ppos, PyObject** pkey, PyOb
}
extern "C" PyObject* PyDict_GetItemString(PyObject* dict, const char* key) noexcept {
if (dict->cls == attrwrapper_cls)
return unwrapAttrWrapper(dict)->getattr(key);
Box* key_s;
try {
key_s = boxString(key);
......
......@@ -594,6 +594,10 @@ Box* listIAdd(BoxedList* self, Box* _rhs) {
int s1 = self->size;
int s2 = rhs->size;
if (s2 == 0)
return self;
self->ensure(s1 + s2);
memcpy(self->elts->elts + s1, rhs->elts->elts, sizeof(rhs->elts->elts[0]) * s2);
......
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