[issue6133] LOAD_CONST followed by LOAD_ATTR can be optimized to just be a LOAD_COST
Raymond Hettinger
report at bugs.python.org
Fri May 29 22:29:01 CEST 2009
Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:
I'm working a better patch now. Will give to collin to review when it's
ready. Here's a draft of the new opcode:
TARGET(LOAD_CONST_ATTR)
u = GETLOCAL(oparg); /* Cached attribute or NULL */
t = TOP(); /* t = (obj, name) where obj is constant */
if (u != NULL) { /* If cache is non-null, use it */
Py_INCREF(u);
SET_TOP(u);
Py_DECREF(t);
FAST_DISPATCH();
}
/* Cache is empty, do regular attribute lookup */
assert(PyTuple_CheckExact(t) && Py_SIZE(t) == 2);
v = PyTuple_GET_ITEM(t, 0);
w = PyTuple_GET_ITEM(t, 1);
x = PyObject_GetAttr(v, w);
Py_DECREF(t);
if (x != NULL) { /* Successful lookup; cache it and return */
SETLOCAL(oparg, x);
Py_INCREF(x);
SET_TOP(x);
break;
}
STACKADJ(-1); /* Attribute not found; goto err handler */
break;
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6133>
_______________________________________
More information about the Python-bugs-list
mailing list