Commit ddec8aee authored by Kevin Modzelewski's avatar Kevin Modzelewski

Switch hidden classes from std::unordered_map<string> to llvm::StringMap

parent 533ea58a
......@@ -649,7 +649,7 @@ BoxedDict* getLocals(bool only_user_visible, bool includeClosure) {
for (; closure != NULL; closure = closure->parent) {
assert(closure->cls == closure_cls);
for (auto& attr_offset : closure->attrs.hcls->attr_offsets) {
const std::string& name = attr_offset.first;
const std::string& name = attr_offset.first();
int offset = attr_offset.second;
Box* val = closure->attrs.attr_list->attrs[offset];
ScopeInfo* scope_info = cf->clfunc->source->getScopeInfo();
......
......@@ -171,12 +171,12 @@ extern "C" Box* dir(Box* obj) {
}
for (auto const& kv : obj->cls->attrs.hcls->attr_offsets) {
listAppend(result, boxString(kv.first));
listAppend(result, boxString(kv.first()));
}
if (obj->cls->instancesHaveHCAttrs()) {
HCAttrs* attrs = obj->getHCAttrsPtr();
for (auto const& kv : attrs->hcls->attr_offsets) {
listAppend(result, boxString(kv.first));
listAppend(result, boxString(kv.first()));
}
}
if (obj->cls->instancesHaveDictAttrs()) {
......
......@@ -469,7 +469,7 @@ const char* getNameOfClass(BoxedClass* cls) {
}
HiddenClass* HiddenClass::getOrMakeChild(const std::string& attr) {
std::unordered_map<std::string, HiddenClass*>::iterator it = children.find(attr);
auto it = children.find(attr);
if (it != children.end())
return it->second;
......@@ -492,9 +492,9 @@ HiddenClass* HiddenClass::delAttrToMakeHC(const std::string& attr) {
std::vector<std::string> new_attrs(attr_offsets.size() - 1);
for (auto it = attr_offsets.begin(); it != attr_offsets.end(); ++it) {
if (it->second < idx)
new_attrs[it->second] = it->first;
new_attrs[it->second] = it->first();
else if (it->second > idx) {
new_attrs[it->second - 1] = it->first;
new_attrs[it->second - 1] = it->first();
}
}
......@@ -647,7 +647,7 @@ void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite
assert(new_hcls->attr_offsets[attr] == numattrs);
#ifndef NDEBUG
for (const auto& p : hcls->attr_offsets) {
assert(new_hcls->attr_offsets[p.first] == p.second);
assert(new_hcls->attr_offsets[p.first()] == p.second);
}
#endif
......@@ -4254,10 +4254,10 @@ extern "C" Box* importStar(Box* _from_module, BoxedModule* to_module) {
HCAttrs* module_attrs = from_module->getHCAttrsPtr();
for (auto& p : module_attrs->hcls->attr_offsets) {
if (p.first[0] == '_')
if (p.first()[0] == '_')
continue;
to_module->setattr(p.first, module_attrs->attr_list->attrs[p.second], NULL);
to_module->setattr(p.first(), module_attrs->attr_list->attrs[p.second], NULL);
}
return None;
......
......@@ -981,7 +981,7 @@ private:
// Iterating over the an attrwrapper (~=dict) just gives the keys, which
// just depends on the hidden class of the object. Let's store only that:
HiddenClass* hcls;
std::unordered_map<std::string, int>::iterator it;
decltype(HiddenClass::attr_offsets)::iterator it;
public:
AttrWrapperIter(AttrWrapper* aw);
......@@ -1088,7 +1088,7 @@ public:
first = false;
BoxedString* v = attrs->attr_list->attrs[p.second]->reprICAsString();
os << p.first << ": " << v->s;
os << p.first().str() << ": " << v->s;
}
os << "})";
return boxString(os.str());
......@@ -1114,7 +1114,7 @@ public:
HCAttrs* attrs = self->b->getHCAttrsPtr();
for (const auto& p : attrs->hcls->attr_offsets) {
listAppend(rtn, boxString(p.first));
listAppend(rtn, boxString(p.first()));
}
return rtn;
}
......@@ -1140,7 +1140,7 @@ public:
HCAttrs* attrs = self->b->getHCAttrsPtr();
for (const auto& p : attrs->hcls->attr_offsets) {
BoxedTuple* t = new BoxedTuple({ boxString(p.first), attrs->attr_list->attrs[p.second] });
BoxedTuple* t = new BoxedTuple({ boxString(p.first()), attrs->attr_list->attrs[p.second] });
listAppend(rtn, t);
}
return rtn;
......@@ -1154,7 +1154,7 @@ public:
HCAttrs* attrs = self->b->getHCAttrsPtr();
for (const auto& p : attrs->hcls->attr_offsets) {
rtn->d[boxString(p.first)] = attrs->attr_list->attrs[p.second];
rtn->d[boxString(p.first())] = attrs->attr_list->attrs[p.second];
}
return rtn;
}
......@@ -1176,7 +1176,7 @@ public:
HCAttrs* attrs = container->b->getHCAttrsPtr();
for (const auto& p : attrs->hcls->attr_offsets) {
self->b->setattr(p.first, attrs->attr_list->attrs[p.second], NULL);
self->b->setattr(p.first(), attrs->attr_list->attrs[p.second], NULL);
}
} else if (_container->cls == dict_cls) {
BoxedDict* container = static_cast<BoxedDict*>(_container);
......@@ -1218,7 +1218,7 @@ Box* AttrWrapperIter::next(Box* _self) {
AttrWrapperIter* self = static_cast<AttrWrapperIter*>(_self);
assert(self->it != self->hcls->attr_offsets.end());
Box* r = boxString(self->it->first);
Box* r = boxString(self->it->first());
++self->it;
return r;
}
......
......@@ -15,6 +15,7 @@
#ifndef PYSTON_RUNTIME_TYPES_H
#define PYSTON_RUNTIME_TYPES_H
#include <llvm/ADT/StringMap.h>
#include <ucontext.h>
#include "Python.h"
......@@ -255,7 +256,11 @@ static_assert(sizeof(pyston::BoxedHeapClass) == sizeof(PyHeapTypeObject), "");
class HiddenClass : public GCAllocated<gc::GCKind::HIDDEN_CLASS> {
private:
HiddenClass() {}
HiddenClass(const HiddenClass* parent) : attr_offsets(parent->attr_offsets) {}
HiddenClass(HiddenClass* parent) : attr_offsets() {
for (auto& p : parent->attr_offsets) {
this->attr_offsets.insert(&p);
}
}
public:
static HiddenClass* makeRoot() {
......@@ -267,8 +272,8 @@ public:
return new HiddenClass();
}
std::unordered_map<std::string, int> attr_offsets;
std::unordered_map<std::string, HiddenClass*> children;
llvm::StringMap<int> attr_offsets;
llvm::StringMap<HiddenClass*> children;
HiddenClass* getOrMakeChild(const std::string& attr);
......
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