Commit 18b34c5f authored by Marius Wachtler's avatar Marius Wachtler

Improve BoxIterator performance by reducing number of const char* / std::string conversions.

parent a6aee748
......@@ -255,7 +255,7 @@ Box* getattr2(Box* obj, Box* _str) {
}
BoxedString* str = static_cast<BoxedString*>(_str);
Box* rtn = getattr_internal(obj, str->s.c_str(), true, true, NULL, NULL);
Box* rtn = getattr_internal(obj, str->s, true, true, NULL, NULL);
if (!rtn) {
fprintf(stderr, "AttributeError: '%s' object has no attribute '%s'\n", getTypeName(obj)->c_str(),
......@@ -273,7 +273,7 @@ Box* getattr3(Box* obj, Box* _str, Box* default_value) {
}
BoxedString* str = static_cast<BoxedString*>(_str);
Box* rtn = getattr_internal(obj, str->s.c_str(), true, true, NULL, NULL);
Box* rtn = getattr_internal(obj, str->s, true, true, NULL, NULL);
if (!rtn) {
return default_value;
......
......@@ -534,7 +534,7 @@ static Box* _handleClsAttr(Box* obj, Box* attr) {
return attr;
}
Box* getclsattr_internal(Box* obj, const char* attr, GetattrRewriteArgs* rewrite_args,
Box* getclsattr_internal(Box* obj, const std::string& attr, GetattrRewriteArgs* rewrite_args,
GetattrRewriteArgs2* rewrite_args2) {
Box* val;
......@@ -653,15 +653,15 @@ static Box* (*runtimeCall1)(Box*, int64_t, Box*) = (Box * (*)(Box*, int64_t, Box
static Box* (*runtimeCall2)(Box*, int64_t, Box*, Box*) = (Box * (*)(Box*, int64_t, Box*, Box*))runtimeCall;
static Box* (*runtimeCall3)(Box*, int64_t, Box*, Box*, Box*) = (Box * (*)(Box*, int64_t, Box*, Box*, Box*))runtimeCall;
Box* getattr_internal(Box* obj, const char* attr, bool check_cls, bool allow_custom, GetattrRewriteArgs* rewrite_args,
GetattrRewriteArgs2* rewrite_args2) {
Box* getattr_internal(Box* obj, const std::string& attr, bool check_cls, bool allow_custom,
GetattrRewriteArgs* rewrite_args, GetattrRewriteArgs2* rewrite_args2) {
if (allow_custom) {
// Don't need to pass icentry args, since we special-case __getattribtue__ and __getattr__ to use
// invalidation rather than guards
Box* getattribute = getclsattr_internal(obj, "__getattribute__", NULL, NULL);
if (getattribute) {
// TODO this is a good candidate for interning?
Box* boxstr = boxStrConstant(attr);
Box* boxstr = boxString(attr);
Box* rtn = runtimeCall1(getattribute, 1, boxstr);
return rtn;
}
......@@ -720,7 +720,7 @@ Box* getattr_internal(Box* obj, const char* attr, bool check_cls, bool allow_cus
// invalidation rather than guards
Box* getattr = getclsattr_internal(obj, "__getattr__", NULL, NULL);
if (getattr) {
Box* boxstr = boxStrConstant(attr);
Box* boxstr = boxString(attr);
Box* rtn = runtimeCall1(getattr, 1, boxstr);
return rtn;
}
......@@ -1173,14 +1173,14 @@ extern "C" Box* callattrInternal(Box* obj, const std::string* attr, LookupScope
if (rewrite_args) {
GetattrRewriteArgs ga_rewrite_args(rewrite_args->rewriter, rewrite_args->obj);
inst_attr = getattr_internal(obj, attr->c_str(), false, true, &ga_rewrite_args, NULL);
inst_attr = getattr_internal(obj, *attr, false, true, &ga_rewrite_args, NULL);
if (!ga_rewrite_args.out_success)
rewrite_args = NULL;
else if (inst_attr)
r_instattr = ga_rewrite_args.out_rtn;
} else {
inst_attr = getattr_internal(obj, attr->c_str(), false, true, NULL, NULL);
inst_attr = getattr_internal(obj, *attr, false, true, NULL, NULL);
}
if (inst_attr) {
......@@ -1223,14 +1223,14 @@ extern "C" Box* callattrInternal(Box* obj, const std::string* attr, LookupScope
GetattrRewriteArgs ga_rewrite_args(rewrite_args->rewriter, r_cls);
r_cls.assertValid();
clsattr = getattr_internal(obj->cls, attr->c_str(), false, false, &ga_rewrite_args, NULL);
clsattr = getattr_internal(obj->cls, *attr, false, false, &ga_rewrite_args, NULL);
if (!ga_rewrite_args.out_success)
rewrite_args = NULL;
else if (clsattr)
r_clsattr = ga_rewrite_args.out_rtn.move(-1);
} else {
clsattr = getattr_internal(obj->cls, attr->c_str(), false, false, NULL, NULL);
clsattr = getattr_internal(obj->cls, *attr, false, false, NULL, NULL);
}
}
......@@ -1731,7 +1731,7 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
// TODO patch these cases
std::string rop_name = getReverseOpName(op_type);
Box* rattr_func = getattr_internal(rhs->cls, rop_name.c_str(), false, false, NULL, NULL);
Box* rattr_func = getattr_internal(rhs->cls, rop_name, false, false, NULL, NULL);
if (rattr_func) {
Box* rtn = runtimeCall2(rattr_func, 2, rhs, lhs);
if (rtn != NotImplemented) {
......@@ -1929,7 +1929,7 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
}
std::string rop_name = getReverseOpName(op_type);
Box* rattr_func = getattr_internal(rhs->cls, rop_name.c_str(), false, false, NULL, NULL);
Box* rattr_func = getattr_internal(rhs->cls, rop_name, false, false, NULL, NULL);
if (rattr_func) {
Box* rtn = runtimeCall2(rattr_func, 2, rhs, lhs);
if (rtn != NotImplemented) {
......@@ -2020,7 +2020,7 @@ extern "C" Box* unaryop(Box* operand, int op_type) {
std::string op_name = getOpName(op_type);
Box* attr_func = getclsattr_internal(operand, op_name.c_str(), NULL, NULL);
Box* attr_func = getclsattr_internal(operand, op_name, NULL, NULL);
ASSERT(attr_func, "%s.%s", getTypeName(operand)->c_str(), op_name.c_str());
......
......@@ -65,8 +65,8 @@ extern "C" void assertFail(BoxedModule* inModule, Box* msg);
struct CompareRewriteArgs;
Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrite_args);
Box* getattr_internal(Box* obj, const char* attr, bool check_cls, bool allow_custom, GetattrRewriteArgs* rewrite_args,
GetattrRewriteArgs2* rewrite_args2);
Box* getattr_internal(Box* obj, const std::string& attr, bool check_cls, bool allow_custom,
GetattrRewriteArgs* rewrite_args, GetattrRewriteArgs2* rewrite_args2);
extern "C" void raiseAttributeErrorStr(const char* typeName, const char* attr) __attribute__((__noreturn__));
extern "C" void raiseAttributeError(Box* obj, const char* attr) __attribute__((__noreturn__));
......
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