aboutsummaryrefslogtreecommitdiff
path: root/lib/utils.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-12 16:10:03 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-12 16:10:03 +0300
commita132841fb920f6815eb6d153f4329242354f1cae (patch)
tree7e78973f3ff2a365953567ebf528cecbda82304e /lib/utils.js
parent2b1e4628e0ee3e73d2e9d00635e51067ec36cd52 (diff)
downloadtracifyjs-a132841fb920f6815eb6d153f4329242354f1cae.tar.gz
tracifyjs-a132841fb920f6815eb6d153f4329242354f1cae.zip
more AST_If optimizations
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/utils.js b/lib/utils.js
index e9a2f80a..6f8334ee 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -113,6 +113,8 @@ var MAP = (function(){
var ret = [], top = [], i;
function doit() {
var val = f.call(o, a[i], i);
+ var is_last = val instanceof Last;
+ if (is_last) val = val.v;
if (val instanceof AtTop) {
val = val.v;
if (val instanceof Splice) {
@@ -128,16 +130,23 @@ var MAP = (function(){
ret.push(val);
}
}
+ return is_last;
};
- if (a instanceof Array) for (i = 0; i < a.length; ++i) doit();
- else for (i in a) if (HOP(a, i)) doit();
+ if (a instanceof Array) {
+ for (i = 0; i < a.length; ++i) if (doit()) break;
+ }
+ else {
+ for (i in a) if (HOP(a, i)) if (doit()) break;
+ }
return top.concat(ret);
};
MAP.at_top = function(val) { return new AtTop(val) };
MAP.splice = function(val) { return new Splice(val) };
+ MAP.last = function(val) { return new Last(val) };
var skip = MAP.skip = {};
function AtTop(val) { this.v = val };
function Splice(val) { this.v = val };
+ function Last(val) { this.v = val };
return MAP;
})();