aboutsummaryrefslogtreecommitdiff
path: root/src/parseTools.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-03 16:07:11 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-11-03 16:07:11 -0700
commitd0712e1e913ff078bd32979cffc8e21fb098767c (patch)
tree63b6666c9387829b297115a1c00e3773bdc067ce /src/parseTools.js
parenta2449f950efe0fb00dc5732d9a82f5baa4187865 (diff)
refactor getFastValue
Diffstat (limited to 'src/parseTools.js')
-rw-r--r--src/parseTools.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 05f12f61..89b5ac98 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -900,12 +900,17 @@ function makeCopyValues(dest, src, num, type, modifier) {
// Given two values and an operation, returns the result of that operation.
// Tries to do as much as possible at compile time.
function getFastValue(a, op, b) {
+ a = a.toString();
+ b = b.toString();
if (isNumber(a) && isNumber(b)) {
return eval(a + op + b).toString();
}
+ if (op in set('+', '*') && isNumber(a)) { // if one of them is a number, keep it last
+ var c = b;
+ b = a;
+ a = c;
+ }
if (op in set('*', '/')) {
- if (!a) a = '1';
- if (!b) b = '1';
if (op == '*') {
if (a == 0 || b == 0) {
return '0';
@@ -922,8 +927,6 @@ function getFastValue(a, op, b) {
}
}
} else if (op in set('+', '-')) {
- if (!a) a = '0';
- if (!b) b = '0';
if (b[0] == '-') {
op = op == '+' ? '-' : '+';
b = b.substr(1);