Skip to content

Commit baae318

Browse files
committed
microoptimize: PyDict_Contains(attrwrapper_cls, str)
1 parent dcea152 commit baae318

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/runtime/dict.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ extern "C" int PyDict_Contains(PyObject* op, PyObject* key) noexcept {
473473

474474
try {
475475
if (op->cls == attrwrapper_cls) {
476+
if (key->cls == str_cls) {
477+
BoxedString* key_str = (BoxedString*)key;
478+
internStringMortalInplace(key_str);
479+
return unwrapAttrWrapper(op)->hasattr(key_str);
480+
}
481+
476482
Box* rtn = PyObject_CallMethod(op, "__contains__", "O", key);
477483
if (!rtn)
478484
return -1;

0 commit comments

Comments
 (0)