Commit 6a63b319 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Faster version of attrwrapper.clear()

parent a921480a
......@@ -500,6 +500,8 @@ public:
bool nonzeroIC();
Box* hasnextOrNullIC();
Box* nextIC();
friend class AttrWrapper;
};
static_assert(offsetof(Box, cls) == offsetof(struct _object, ob_type), "");
......
......@@ -536,6 +536,8 @@ HiddenClass* HiddenClass::getOrMakeChild(const std::string& attr) {
HiddenClass* HiddenClass::getAttrwrapperChild() {
assert(type == NORMAL);
assert(attrwrapper_offset == -1);
if (!attrwrapper_child) {
attrwrapper_child = new HiddenClass(this);
attrwrapper_child->attrwrapper_offset = this->attributeArraySize();
......
......@@ -1553,12 +1553,12 @@ public:
HCAttrs* attrs = self->b->getHCAttrsPtr();
RELEASE_ASSERT(attrs->hcls->type == HiddenClass::NORMAL || attrs->hcls->type == HiddenClass::SINGLETON, "");
while (true) {
const auto& attrMap = attrs->hcls->getStrAttrOffsets();
if (attrMap.size() == 0)
break;
self->b->delattr(attrMap.begin()->first(), NULL);
}
// Clear the attrs array:
new ((void*)attrs) HCAttrs(root_hcls);
// Add the existing attrwrapper object (ie self) back as the attrwrapper:
self->b->appendNewHCAttr(self, NULL);
attrs->hcls = attrs->hcls->getAttrwrapperChild();
return None;
}
......
......@@ -44,6 +44,8 @@ class C(object):
return 0
c = C()
c.attr = "test"
c.__dict__.clear()
d1 = c.__dict__
d1.clear()
print hasattr(c, "attr")
print hasattr(c, "foo")
print c.__dict__ is d1
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