speed up!

This commit is contained in:
blueloveTH 2022-11-20 17:49:40 +08:00
parent f4f122c258
commit 486bf3b898
2 changed files with 13 additions and 9 deletions

View File

@ -117,6 +117,7 @@ namespace pkpy {
other.clear(); other.clear();
} }
// deprecated, this is very slow, do not use it!!!
ArgList(std::initializer_list<PyVar> args){ ArgList(std::initializer_list<PyVar> args){
__tryAlloc(args.size()); __tryAlloc(args.size());
int i = 0; int i = 0;

View File

@ -158,23 +158,26 @@ private:
case OP_POP_TOP: frame->popValue(this); break; case OP_POP_TOP: frame->popValue(this); break;
case OP_BINARY_OP: case OP_BINARY_OP:
{ {
PyVar rhs = frame->popValue(this); pkpy::ArgList args(2);
PyVar lhs = frame->popValue(this); args[1] = frame->popValue(this);
frame->push(fastCall(lhs, BINARY_SPECIAL_METHODS[byte.arg], {lhs,std::move(rhs)})); args[0] = frame->popValue(this);
frame->push(fastCall(args[0], BINARY_SPECIAL_METHODS[byte.arg], std::move(args)));
} break; } break;
case OP_BITWISE_OP: case OP_BITWISE_OP:
{ {
PyVar rhs = frame->popValue(this); pkpy::ArgList args(2);
PyVar lhs = frame->popValue(this); args[1] = frame->popValue(this);
frame->push(fastCall(lhs, BITWISE_SPECIAL_METHODS[byte.arg], {lhs,std::move(rhs)})); args[0] = frame->popValue(this);
frame->push(fastCall(args[0], BITWISE_SPECIAL_METHODS[byte.arg], std::move(args)));
} break; } break;
case OP_COMPARE_OP: case OP_COMPARE_OP:
{ {
PyVar rhs = frame->popValue(this); pkpy::ArgList args(2);
PyVar lhs = frame->popValue(this); args[1] = frame->popValue(this);
args[0] = frame->popValue(this);
// for __ne__ we use the negation of __eq__ // for __ne__ we use the negation of __eq__
int op = byte.arg == 3 ? 2 : byte.arg; int op = byte.arg == 3 ? 2 : byte.arg;
PyVar res = fastCall(lhs, CMP_SPECIAL_METHODS[op], {lhs,std::move(rhs)}); PyVar res = fastCall(args[0], CMP_SPECIAL_METHODS[op], std::move(args));
if(op != byte.arg) res = PyBool(!PyBool_AS_C(res)); if(op != byte.arg) res = PyBool(!PyBool_AS_C(res));
frame->push(std::move(res)); frame->push(std::move(res));
} break; } break;