PRIVATE: Reduce Datum copies slightly
This commit is contained in:
parent
73df4773bb
commit
06e3537155
2 changed files with 29 additions and 41 deletions
|
@ -77,11 +77,11 @@ void SettingMaps::init() {
|
||||||
g_vm->_stackp = Gen::g_vm->_stack;
|
g_vm->_stackp = Gen::g_vm->_stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingMaps::save(char *name) {
|
void SettingMaps::save(const char *name) {
|
||||||
_map.setVal(name, _setting);
|
_map.setVal(name, _setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingMaps::load(Common::String &name) {
|
void SettingMaps::load(const Common::String &name) {
|
||||||
assert(_map.contains(name));
|
assert(_map.contains(name));
|
||||||
_setting = _map.getVal(name);
|
_setting = _map.getVal(name);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ Datum pop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* push d onto stack */
|
/* push d onto stack */
|
||||||
int push(Datum d) {
|
int push(const Datum &d) {
|
||||||
assert (!(g_vm->_stackp >= &g_vm->_stack[NSTACK]));
|
assert (!(g_vm->_stackp >= &g_vm->_stack[NSTACK]));
|
||||||
*g_vm->_stackp++ = d;
|
*g_vm->_stackp++ = d;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -144,14 +144,13 @@ int varpush() { /* push variable onto stack */
|
||||||
}
|
}
|
||||||
|
|
||||||
int funcpush() {
|
int funcpush() {
|
||||||
Datum s, n, arg;
|
Datum s = pop();
|
||||||
s = pop();
|
Datum n = pop();
|
||||||
n = pop();
|
|
||||||
ArgArray args;
|
ArgArray args;
|
||||||
|
|
||||||
debugC(1, kPrivateDebugCode, "executing %s with %d params", s.u.str, n.u.val);
|
debugC(1, kPrivateDebugCode, "executing %s with %d params", s.u.str, n.u.val);
|
||||||
for (int i = 0; i < n.u.val; i++) {
|
for (int i = 0; i < n.u.val; i++) {
|
||||||
arg = pop();
|
Datum arg = pop();
|
||||||
args.insert(args.begin(), arg) ;
|
args.insert(args.begin(), arg) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,8 +160,7 @@ int funcpush() {
|
||||||
|
|
||||||
/* evaluate variable on stack */
|
/* evaluate variable on stack */
|
||||||
int eval() {
|
int eval() {
|
||||||
Datum d;
|
Datum d = pop();
|
||||||
d = pop();
|
|
||||||
if (d.u.sym->type == NUM) {
|
if (d.u.sym->type == NUM) {
|
||||||
d.type = NUM;
|
d.type = NUM;
|
||||||
d.u.val = d.u.sym->u.val;
|
d.u.val = d.u.sym->u.val;
|
||||||
|
@ -184,9 +182,8 @@ int eval() {
|
||||||
|
|
||||||
/* add top two elems on stack */
|
/* add top two elems on stack */
|
||||||
int add() {
|
int add() {
|
||||||
Datum d1, d2;
|
Datum d2 = pop();
|
||||||
d2 = pop();
|
Datum d1 = pop();
|
||||||
d1 = pop();
|
|
||||||
if (d1.type == NAME) {
|
if (d1.type == NAME) {
|
||||||
d1.u.val = d1.u.sym->u.val;
|
d1.u.val = d1.u.sym->u.val;
|
||||||
d1.type = NUM;
|
d1.type = NUM;
|
||||||
|
@ -207,8 +204,7 @@ int add() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int negate() {
|
int negate() {
|
||||||
Datum d;
|
Datum d = pop();
|
||||||
d = pop();
|
|
||||||
int v;
|
int v;
|
||||||
if (d.type == NAME) {
|
if (d.type == NAME) {
|
||||||
//debug("negating %s", d.u.sym->name->c_str());
|
//debug("negating %s", d.u.sym->name->c_str());
|
||||||
|
@ -225,9 +221,8 @@ int negate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int gt() {
|
int gt() {
|
||||||
Datum d1, d2;
|
Datum d2 = pop();
|
||||||
d2 = pop();
|
Datum d1 = pop();
|
||||||
d1 = pop();
|
|
||||||
if (d1.type == NAME) {
|
if (d1.type == NAME) {
|
||||||
//char *name = d1.u.sym->name->c_str();
|
//char *name = d1.u.sym->name->c_str();
|
||||||
//debug("eval %s to %d",
|
//debug("eval %s to %d",
|
||||||
|
@ -248,9 +243,8 @@ int gt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int lt() {
|
int lt() {
|
||||||
Datum d1, d2;
|
Datum d2 = pop();
|
||||||
d2 = pop();
|
Datum d1 = pop();
|
||||||
d1 = pop();
|
|
||||||
if (d1.type == NAME) {
|
if (d1.type == NAME) {
|
||||||
//char *name = d1.u.sym->name->c_str();
|
//char *name = d1.u.sym->name->c_str();
|
||||||
//debug("eval %s to %d",
|
//debug("eval %s to %d",
|
||||||
|
@ -271,9 +265,8 @@ int lt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ge() {
|
int ge() {
|
||||||
Datum d1, d2;
|
Datum d2 = pop();
|
||||||
d2 = pop();
|
Datum d1 = pop();
|
||||||
d1 = pop();
|
|
||||||
if (d1.type == NAME) {
|
if (d1.type == NAME) {
|
||||||
//char *name = d1.u.sym->name->c_str();
|
//char *name = d1.u.sym->name->c_str();
|
||||||
//debug("eval %s to %d",
|
//debug("eval %s to %d",
|
||||||
|
@ -294,9 +287,8 @@ int ge() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int le() {
|
int le() {
|
||||||
Datum d1, d2;
|
Datum d2 = pop();
|
||||||
d2 = pop();
|
Datum d1 = pop();
|
||||||
d1 = pop();
|
|
||||||
if (d1.type == NAME) {
|
if (d1.type == NAME) {
|
||||||
//char *name = d1.u.sym->name->c_str();
|
//char *name = d1.u.sym->name->c_str();
|
||||||
//debug("eval %s to %d",
|
//debug("eval %s to %d",
|
||||||
|
@ -317,9 +309,8 @@ int le() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int eq() {
|
int eq() {
|
||||||
Datum d1, d2;
|
Datum d2 = pop();
|
||||||
d2 = pop();
|
Datum d1 = pop();
|
||||||
d1 = pop();
|
|
||||||
if (d1.type == NAME) {
|
if (d1.type == NAME) {
|
||||||
//char *name = d1.u.sym->name->c_str();
|
//char *name = d1.u.sym->name->c_str();
|
||||||
//debug("eval %s to %d",
|
//debug("eval %s to %d",
|
||||||
|
@ -340,9 +331,8 @@ int eq() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ne() {
|
int ne() {
|
||||||
Datum d1, d2;
|
Datum d2 = pop();
|
||||||
d2 = pop();
|
Datum d1 = pop();
|
||||||
d1 = pop();
|
|
||||||
if (d1.type == NAME) {
|
if (d1.type == NAME) {
|
||||||
d1.u.val = d1.u.sym->u.val;
|
d1.u.val = d1.u.sym->u.val;
|
||||||
d1.type = NUM;
|
d1.type = NUM;
|
||||||
|
@ -359,7 +349,7 @@ int ne() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* install one instruction or operand */
|
/* install one instruction or operand */
|
||||||
Inst *code(Inst f) {
|
Inst *code(const Inst &f) {
|
||||||
//debugC(1, kPrivateDebugCode, "pushing code at %x", progp);
|
//debugC(1, kPrivateDebugCode, "pushing code at %x", progp);
|
||||||
Inst *oprogp = g_vm->_progp;
|
Inst *oprogp = g_vm->_progp;
|
||||||
assert (!(g_vm->_progp >= &g_vm->_prog[NPROG]));
|
assert (!(g_vm->_progp >= &g_vm->_prog[NPROG]));
|
||||||
|
@ -368,12 +358,11 @@ Inst *code(Inst f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ifcode() {
|
int ifcode() {
|
||||||
Datum d;
|
|
||||||
Inst *savepc = g_vm->_pc; /* then part */
|
Inst *savepc = g_vm->_pc; /* then part */
|
||||||
debugC(1, kPrivateDebugCode, "ifcode: evaluating condition");
|
debugC(1, kPrivateDebugCode, "ifcode: evaluating condition");
|
||||||
|
|
||||||
execute(savepc+3); /* condition */
|
execute(savepc+3); /* condition */
|
||||||
d = pop();
|
Datum d = pop();
|
||||||
|
|
||||||
debugC(1, kPrivateDebugCode, "ifcode: selecting branch");
|
debugC(1, kPrivateDebugCode, "ifcode: selecting branch");
|
||||||
|
|
||||||
|
@ -395,8 +384,7 @@ int ifcode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int randbool() {
|
int randbool() {
|
||||||
Datum d;
|
Datum d = pop();
|
||||||
d = pop();
|
|
||||||
|
|
||||||
int v = g_private->getRandomBool(d.u.val);
|
int v = g_private->getRandomBool(d.u.val);
|
||||||
|
|
||||||
|
|
|
@ -76,8 +76,8 @@ public:
|
||||||
SettingMap _map;
|
SettingMap _map;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void save(char *);
|
void save(const char *);
|
||||||
void load(Common::String &);
|
void load(const Common::String &);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SettingMaps *g_setts;
|
extern SettingMaps *g_setts;
|
||||||
|
@ -107,9 +107,9 @@ public:
|
||||||
extern VM *g_vm;
|
extern VM *g_vm;
|
||||||
|
|
||||||
Datum pop();
|
Datum pop();
|
||||||
int push(Datum);
|
int push(const Datum &);
|
||||||
|
|
||||||
Inst *code(Inst);
|
Inst *code(const Inst &);
|
||||||
int eval();
|
int eval();
|
||||||
int add();
|
int add();
|
||||||
int negate();
|
int negate();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue