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

Improve the performance of sum()

Move some things to calling the *Internal methods,
which don't do patchpoint-checking, which wouldn't apply.

Reduce some unnecessary string-creation.
parent 0637b1b6
......@@ -22,6 +22,7 @@ Some directories are distributed under different licenses, and contain
separate LICENSE files:
- libunwind_patches
- llvm_patches
- clang_patches
Regardless of any separate LICENSE files, all code in this repository
falls under the following disclaimer:
......
From b1b7a1de4895a5d821592f0221c3ae0b14200ff1 Mon Sep 17 00:00:00 2001
From: Kevin Modzelewski <kevmod@gmail.com>
From: Kevin Modzelewski <kmod@dropbox.com>
Date: Tue, 27 May 2014 17:03:25 -0700
Subject: [PATCH] Rename one of scan-builds internal environment variables to not conflict
......
......@@ -129,7 +129,7 @@ extern "C" Box* sum2(Box* container, Box* initial) {
Box* cur = initial;
for (Box* e : container->pyElements()) {
cur = binop(cur, e, AST_TYPE::Add);
cur = binopInternal(cur, e, AST_TYPE::Add, false, NULL);
}
return cur;
}
......
......@@ -173,19 +173,12 @@ static Box* (*typeCallInternal2)(CallRewriteArgs* rewrite_args, int64_t nargs, B
static Box* (*typeCallInternal3)(CallRewriteArgs* rewrite_args, int64_t nargs, Box*, Box*, Box*)
= (Box * (*)(CallRewriteArgs*, int64_t, Box*, Box*, Box*))typeCallInternal;
enum LookupScope {
CLASS_ONLY = 1,
INST_ONLY = 2,
CLASS_OR_INST = 3,
};
bool checkClass(LookupScope scope) {
return (scope & CLASS_ONLY) != 0;
}
bool checkInst(LookupScope scope) {
return (scope & INST_ONLY) != 0;
}
extern "C" Box* callattrInternal(Box* obj, const std::string* attr, LookupScope, CallRewriteArgs* rewrite_args,
int64_t nargs, Box* arg1, Box* arg2, Box* arg3, Box** args);
static Box* (*callattrInternal0)(Box*, const std::string*, LookupScope, CallRewriteArgs*, int64_t)
= (Box * (*)(Box*, const std::string*, LookupScope, CallRewriteArgs*, int64_t))callattrInternal;
static Box* (*callattrInternal1)(Box*, const std::string*, LookupScope, CallRewriteArgs*, int64_t, Box*)
......@@ -1719,9 +1712,9 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
r_rhs.addAttrGuard(BOX_CLS_OFFSET, (intptr_t)rhs->cls);
}
std::string iop_name = getInplaceOpName(op_type);
Box* irtn = NULL;
if (inplace) {
std::string iop_name = getInplaceOpName(op_type);
if (rewrite_args) {
CallRewriteArgs srewrite_args(rewrite_args->rewriter, rewrite_args->lhs);
srewrite_args.arg1 = rewrite_args->rhs;
......@@ -1792,6 +1785,7 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
if (VERBOSITY()) {
if (inplace) {
std::string iop_name = getInplaceOpName(op_type);
if (irtn)
fprintf(stderr, "%s has %s, but returned NotImplemented\n", getTypeName(lhs)->c_str(),
iop_name.c_str());
......
......@@ -70,6 +70,18 @@ extern "C" void checkUnpackingLength(i64 expected, i64 given);
extern "C" void assertNameDefined(bool b, const char* name);
extern "C" void assertFail(BoxedModule* inModule, Box* msg);
class BinopRewriteArgs;
extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, BinopRewriteArgs* rewrite_args);
class CallRewriteArgs;
enum LookupScope {
CLASS_ONLY = 1,
INST_ONLY = 2,
CLASS_OR_INST = 3,
};
extern "C" Box* callattrInternal(Box* obj, const std::string* attr, LookupScope, CallRewriteArgs* rewrite_args,
int64_t nargs, Box* arg1, Box* arg2, Box* arg3, Box** args);
struct CompareRewriteArgs;
Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrite_args);
Box* getattr_internal(Box* obj, const std::string& attr, bool check_cls, bool allow_custom,
......
......@@ -44,9 +44,9 @@ BoxIterator& BoxIterator::operator++() {
static std::string hasnext_str("__hasnext__");
static std::string next_str("next");
Box* hasnext = callattr(iter, &hasnext_str, true, 0, NULL, NULL, NULL, NULL);
Box* hasnext = callattrInternal(iter, &hasnext_str, CLASS_ONLY, NULL, 0, NULL, NULL, NULL, NULL);
if (nonzero(hasnext)) {
value = callattr(iter, &next_str, true, 0, NULL, NULL, NULL, NULL);
value = callattrInternal(iter, &next_str, CLASS_ONLY, NULL, 0, NULL, NULL, NULL, NULL);
} else {
iter = nullptr;
value = nullptr;
......
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