Commit 65e3ce5b authored by Marius Wachtler's avatar Marius Wachtler

Optimize nonzero()

- use callattr directly instead of getattr+runtimeCall
- compvar: teach it that None is never nonzero
parent 0e98930e
...@@ -1878,8 +1878,10 @@ public: ...@@ -1878,8 +1878,10 @@ public:
} }
ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override { ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override {
static BoxedString* attr = internStringImmortal("__nonzero__"); if (cls == None->cls)
return makeBool(false);
static BoxedString* attr = internStringImmortal("__nonzero__");
bool no_attribute = false; bool no_attribute = false;
ConcreteCompilerVariable* called_constant ConcreteCompilerVariable* called_constant
= tryCallattrConstant(emitter, info, var, attr, true, ArgPassSpec(0, 0, 0, 0), {}, NULL, &no_attribute); = tryCallattrConstant(emitter, info, var, attr, true, ArgPassSpec(0, 0, 0, 0), {}, NULL, &no_attribute);
......
...@@ -2456,20 +2456,20 @@ extern "C" bool nonzero(Box* obj) { ...@@ -2456,20 +2456,20 @@ extern "C" bool nonzero(Box* obj) {
static BoxedString* len_str = internStringImmortal("__len__"); static BoxedString* len_str = internStringImmortal("__len__");
// try __nonzero__ // try __nonzero__
GetattrRewriteArgs grewrite_args(rewriter.get(), r_obj, rewriter ? rewriter->getReturnDestination() : Location()); CallRewriteArgs crewrite_args(rewriter.get(), r_obj, rewriter ? rewriter->getReturnDestination() : Location());
Box* func = getclsattrInternal(obj, nonzero_str, rewriter ? &grewrite_args : NULL); Box* rtn = callattrInternal0<CXX>(obj, nonzero_str, CLASS_ONLY, rewriter ? &crewrite_args : NULL, ArgPassSpec(0));
if (!grewrite_args.out_success) if (!crewrite_args.out_success)
rewriter.reset(); rewriter.reset();
if (!func) { if (!rtn) {
// try __len__ // try __len__
grewrite_args crewrite_args
= GetattrRewriteArgs(rewriter.get(), r_obj, rewriter ? rewriter->getReturnDestination() : Location()); = CallRewriteArgs(rewriter.get(), r_obj, rewriter ? rewriter->getReturnDestination() : Location());
func = getclsattrInternal(obj, len_str, rewriter ? &grewrite_args : NULL); rtn = callattrInternal0<CXX>(obj, len_str, CLASS_ONLY, rewriter ? &crewrite_args : NULL, ArgPassSpec(0));
if (!grewrite_args.out_success) if (!crewrite_args.out_success)
rewriter.reset(); rewriter.reset();
if (func == NULL) { if (rtn == NULL) {
ASSERT(obj->cls->is_user_defined || obj->cls == classobj_cls || obj->cls == type_cls ASSERT(obj->cls->is_user_defined || obj->cls == classobj_cls || obj->cls == type_cls
|| isSubclass(obj->cls, Exception) || obj->cls == file_cls || obj->cls == traceback_cls || isSubclass(obj->cls, Exception) || obj->cls == file_cls || obj->cls == traceback_cls
|| obj->cls == instancemethod_cls || obj->cls == module_cls || obj->cls == capifunc_cls || obj->cls == instancemethod_cls || obj->cls == module_cls || obj->cls == capifunc_cls
...@@ -2485,11 +2485,8 @@ extern "C" bool nonzero(Box* obj) { ...@@ -2485,11 +2485,8 @@ extern "C" bool nonzero(Box* obj) {
return true; return true;
} }
} }
CallRewriteArgs cargs(rewriter.get(), grewrite_args.out_rtn, if (crewrite_args.out_success) {
rewriter ? rewriter->getReturnDestination() : Location()); RewriterVar* b = rewriter->call(false, (void*)nonzeroHelper, crewrite_args.out_rtn);
Box* rtn = runtimeCallInternal0<CXX>(func, rewriter ? &cargs : NULL, ArgPassSpec(0));
if (cargs.out_success) {
RewriterVar* b = rewriter->call(false, (void*)nonzeroHelper, cargs.out_rtn);
rewriter->commitReturning(b); rewriter->commitReturning(b);
} }
return nonzeroHelper(rtn); return nonzeroHelper(rtn);
......
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