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

Faster version of attrwrapper.clear()

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