Commit f8de4f1a authored by Kevin Modzelewski's avatar Kevin Modzelewski

Cut down on unnecessary string copies

parent 6eb1b53f
...@@ -202,8 +202,7 @@ private: ...@@ -202,8 +202,7 @@ private:
CompilerType* right = getType(node->right); CompilerType* right = getType(node->right);
// TODO this isn't the exact behavior // TODO this isn't the exact behavior
std::string name = getOpName(node->op_type); std::string name = getInplaceOpName(node->op_type);
name = "__i" + name.substr(2);
CompilerType* attr_type = left->getattrType(&name, true); CompilerType* attr_type = left->getattrType(&name, true);
if (attr_type == UNDEF) if (attr_type == UNDEF)
...@@ -230,7 +229,7 @@ private: ...@@ -230,7 +229,7 @@ private:
CompilerType* right = getType(node->right); CompilerType* right = getType(node->right);
// TODO this isn't the exact behavior // TODO this isn't the exact behavior
std::string name = getOpName(node->op_type); const std::string& name = getOpName(node->op_type);
CompilerType* attr_type = left->getattrType(&name, true); CompilerType* attr_type = left->getattrType(&name, true);
if (attr_type == UNDEF) if (attr_type == UNDEF)
...@@ -304,7 +303,7 @@ private: ...@@ -304,7 +303,7 @@ private:
return BOOL; return BOOL;
} }
std::string name = getOpName(node->ops[0]); const std::string& name = getOpName(node->ops[0]);
CompilerType* attr_type = left->getattrType(&name, true); CompilerType* attr_type = left->getattrType(&name, true);
if (attr_type == UNDEF) if (attr_type == UNDEF)
...@@ -409,7 +408,7 @@ private: ...@@ -409,7 +408,7 @@ private:
CompilerType* operand = getType(node->operand); CompilerType* operand = getType(node->operand);
// TODO this isn't the exact behavior // TODO this isn't the exact behavior
std::string name = getOpName(node->op_type); const std::string& name = getOpName(node->op_type);
CompilerType* attr_type = operand->getattrType(&name, true); CompilerType* attr_type = operand->getattrType(&name, true);
std::vector<CompilerType*> arg_types; std::vector<CompilerType*> arg_types;
return attr_type->callType(arg_types); return attr_type->callType(arg_types);
......
...@@ -90,60 +90,66 @@ std::string getInplaceOpSymbol(int op_type) { ...@@ -90,60 +90,66 @@ std::string getInplaceOpSymbol(int op_type) {
return std::string(getOpSymbol(op_type)) + '='; return std::string(getOpSymbol(op_type)) + '=';
} }
std::string getOpName(int op_type) { const static std::string strAdd("__add__"), strBitAnd("__and__"), strBitOr("__or__"), strBitXor("__xor__"),
strDiv("__div__"), strTrueDiv("__truediv__"), strEq("__eq__"), strFloorDiv("__floordiv__"), strLShift("__lshift__"),
strLt("__lt__"), strLtE("__le__"), strGt("__gt__"), strGtE("__ge__"), strIn("__contains__"),
strInvert("__invert__"), strMod("__mod__"), strMult("__mul__"), strNot("__nonzero__"), strNotEq("__ne__"),
strPow("__pow__"), strRShift("__rshift__"), strSub("__sub__"), strUAdd("__pos__"), strUSub("__neg__");
const std::string& getOpName(int op_type) {
assert(op_type != AST_TYPE::Is); assert(op_type != AST_TYPE::Is);
assert(op_type != AST_TYPE::IsNot); assert(op_type != AST_TYPE::IsNot);
switch (op_type) { switch (op_type) {
case AST_TYPE::Add: case AST_TYPE::Add:
return "__add__"; return strAdd;
case AST_TYPE::BitAnd: case AST_TYPE::BitAnd:
return "__and__"; return strBitAnd;
case AST_TYPE::BitOr: case AST_TYPE::BitOr:
return "__or__"; return strBitOr;
case AST_TYPE::BitXor: case AST_TYPE::BitXor:
return "__xor__"; return strBitXor;
case AST_TYPE::Div: case AST_TYPE::Div:
if (FUTURE_DIVISION) if (FUTURE_DIVISION)
return "__truediv__"; return strTrueDiv;
else else
return "__div__"; return strDiv;
case AST_TYPE::Eq: case AST_TYPE::Eq:
return "__eq__"; return strEq;
case AST_TYPE::FloorDiv: case AST_TYPE::FloorDiv:
return "__floordiv__"; return strFloorDiv;
case AST_TYPE::LShift: case AST_TYPE::LShift:
return "__lshift__"; return strLShift;
case AST_TYPE::Lt: case AST_TYPE::Lt:
return "__lt__"; return strLt;
case AST_TYPE::LtE: case AST_TYPE::LtE:
return "__le__"; return strLtE;
case AST_TYPE::Gt: case AST_TYPE::Gt:
return "__gt__"; return strGt;
case AST_TYPE::GtE: case AST_TYPE::GtE:
return "__ge__"; return strGtE;
case AST_TYPE::In: case AST_TYPE::In:
return "__contains__"; return strIn;
case AST_TYPE::Invert: case AST_TYPE::Invert:
return "__invert__"; return strInvert;
case AST_TYPE::Mod: case AST_TYPE::Mod:
return "__mod__"; return strMod;
case AST_TYPE::Mult: case AST_TYPE::Mult:
return "__mul__"; return strMult;
case AST_TYPE::Not: case AST_TYPE::Not:
return "__nonzero__"; return strNot;
case AST_TYPE::NotEq: case AST_TYPE::NotEq:
return "__ne__"; return strNotEq;
case AST_TYPE::Pow: case AST_TYPE::Pow:
return "__pow__"; return strPow;
case AST_TYPE::RShift: case AST_TYPE::RShift:
return "__rshift__"; return strRShift;
case AST_TYPE::Sub: case AST_TYPE::Sub:
return "__sub__"; return strSub;
case AST_TYPE::UAdd: case AST_TYPE::UAdd:
return "__pos__"; return strUAdd;
case AST_TYPE::USub: case AST_TYPE::USub:
return "__neg__"; return strUSub;
default: default:
fprintf(stderr, "Unknown op type (" __FILE__ ":" STRINGIFY(__LINE__) "): %d\n", op_type); fprintf(stderr, "Unknown op type (" __FILE__ ":" STRINGIFY(__LINE__) "): %d\n", op_type);
abort(); abort();
...@@ -151,7 +157,7 @@ std::string getOpName(int op_type) { ...@@ -151,7 +157,7 @@ std::string getOpName(int op_type) {
} }
std::string getInplaceOpName(int op_type) { std::string getInplaceOpName(int op_type) {
std::string normal_name = getOpName(op_type); const std::string& normal_name = getOpName(op_type);
return "__i" + normal_name.substr(2); return "__i" + normal_name.substr(2);
} }
...@@ -172,7 +178,7 @@ std::string getReverseOpName(int op_type) { ...@@ -172,7 +178,7 @@ std::string getReverseOpName(int op_type) {
if (op_type == AST_TYPE::Eq) if (op_type == AST_TYPE::Eq)
return getOpName(AST_TYPE::Eq); return getOpName(AST_TYPE::Eq);
std::string normal_name = getOpName(op_type); const std::string& normal_name = getOpName(op_type);
return "__r" + normal_name.substr(2); return "__r" + normal_name.substr(2);
} }
......
...@@ -1114,6 +1114,10 @@ template <class T, class R> void findNodes(const R& roots, std::vector<T*>& outp ...@@ -1114,6 +1114,10 @@ template <class T, class R> void findNodes(const R& roots, std::vector<T*>& outp
} }
llvm::StringRef getOpSymbol(int op_type); llvm::StringRef getOpSymbol(int op_type);
const std::string& getOpName(int op_type);
std::string getReverseOpName(int op_type);
std::string getInplaceOpName(int op_type);
std::string getInplaceOpSymbol(int op_type);
}; };
#endif #endif
...@@ -227,11 +227,6 @@ CLFunction* unboxRTFunction(Box*); ...@@ -227,11 +227,6 @@ CLFunction* unboxRTFunction(Box*);
extern "C" CompiledFunction* resolveCLFunc(CLFunction* f, int64_t nargs, Box* arg1, Box* arg2, Box* arg3, Box** args); extern "C" CompiledFunction* resolveCLFunc(CLFunction* f, int64_t nargs, Box* arg1, Box* arg2, Box* arg3, Box** args);
extern "C" Box* callCompiledFunc(CompiledFunction* cf, int64_t nargs, Box* arg1, Box* arg2, Box* arg3, Box** args); extern "C" Box* callCompiledFunc(CompiledFunction* cf, int64_t nargs, Box* arg1, Box* arg2, Box* arg3, Box** args);
std::string getOpName(int op_type);
std::string getReverseOpName(int op_type);
std::string getInplaceOpName(int op_type);
std::string getInplaceOpSymbol(int op_type);
typedef bool i1; typedef bool i1;
typedef int64_t i64; typedef int64_t i64;
......
...@@ -1740,7 +1740,7 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin ...@@ -1740,7 +1740,7 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
std::string op_name = getOpName(op_type); const std::string& op_name = getOpName(op_type);
Box* lrtn; Box* lrtn;
if (rewrite_args) { if (rewrite_args) {
CallRewriteArgs srewrite_args(rewrite_args->rewriter, rewrite_args->lhs); CallRewriteArgs srewrite_args(rewrite_args->rewriter, rewrite_args->lhs);
...@@ -1938,7 +1938,7 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit ...@@ -1938,7 +1938,7 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
rewrite_args->rhs.addAttrGuard(BOX_CLS_OFFSET, (intptr_t)rhs->cls); rewrite_args->rhs.addAttrGuard(BOX_CLS_OFFSET, (intptr_t)rhs->cls);
} }
std::string op_name = getOpName(op_type); const std::string& op_name = getOpName(op_type);
Box* lrtn; Box* lrtn;
if (rewrite_args) { if (rewrite_args) {
...@@ -2049,7 +2049,7 @@ extern "C" Box* unaryop(Box* operand, int op_type) { ...@@ -2049,7 +2049,7 @@ extern "C" Box* unaryop(Box* operand, int op_type) {
static StatCounter slowpath_unaryop("slowpath_unaryop"); static StatCounter slowpath_unaryop("slowpath_unaryop");
slowpath_unaryop.log(); slowpath_unaryop.log();
std::string op_name = getOpName(op_type); const std::string& op_name = getOpName(op_type);
Box* attr_func = getclsattr_internal(operand, op_name, NULL, NULL); Box* attr_func = getclsattr_internal(operand, op_name, NULL, NULL);
......
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