mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
optimizing the output of compiled splat arguments.
This commit is contained in:
@@ -222,8 +222,7 @@
|
||||
};
|
||||
Lexer.prototype.balancedToken = function() {
|
||||
var delimited;
|
||||
var _d = arguments.length, _e = _d >= 1;
|
||||
delimited = __slice.call(arguments, 0, _d - 0);
|
||||
delimited = __slice.call(arguments, 0);
|
||||
return this.balancedString(this.chunk, delimited);
|
||||
};
|
||||
Lexer.prototype.lineToken = function() {
|
||||
|
||||
26
lib/nodes.js
26
lib/nodes.js
@@ -1031,20 +1031,24 @@
|
||||
return (typeof (_b = this.index) !== "undefined" && _b !== null) ? this.compileParam(o) : this.name.compile(o);
|
||||
};
|
||||
SplatNode.prototype.compileParam = function(o) {
|
||||
var _b, _c, idx, len, name, pos, trailing, variadic;
|
||||
var _b, _c, end, idx, len, name, pos, trailing, variadic;
|
||||
name = this.name.compile(o);
|
||||
o.scope.find(name);
|
||||
len = o.scope.freeVariable();
|
||||
o.scope.assign(len, "arguments.length");
|
||||
variadic = o.scope.freeVariable();
|
||||
o.scope.assign(variadic, ("" + len + " >= " + this.arglength));
|
||||
_b = this.trailings;
|
||||
for (idx = 0, _c = _b.length; idx < _c; idx++) {
|
||||
trailing = _b[idx];
|
||||
pos = this.trailings.length - idx;
|
||||
o.scope.assign(trailing.compile(o), ("arguments[" + variadic + " ? " + len + " - " + pos + " : " + (this.index + idx) + "]"));
|
||||
end = '';
|
||||
if (this.trailings.length) {
|
||||
len = o.scope.freeVariable();
|
||||
o.scope.assign(len, "arguments.length");
|
||||
variadic = o.scope.freeVariable();
|
||||
o.scope.assign(variadic, ("" + len + " >= " + this.arglength));
|
||||
end = this.trailings.length ? (", " + len + " - " + (this.trailings.length)) : null;
|
||||
_b = this.trailings;
|
||||
for (idx = 0, _c = _b.length; idx < _c; idx++) {
|
||||
trailing = _b[idx];
|
||||
pos = this.trailings.length - idx;
|
||||
o.scope.assign(trailing.compile(o), ("arguments[" + variadic + " ? " + len + " - " + pos + " : " + (this.index + idx) + "]"));
|
||||
}
|
||||
}
|
||||
return "" + name + " = " + (utility('slice')) + ".call(arguments, " + this.index + ", " + len + " - " + (this.trailings.length) + ")";
|
||||
return "" + name + " = " + (utility('slice')) + ".call(arguments, " + this.index + end + ")";
|
||||
};
|
||||
SplatNode.prototype.compileValue = function(o, name, index, trailings) {
|
||||
var trail;
|
||||
|
||||
@@ -922,14 +922,17 @@ exports.SplatNode: class SplatNode extends BaseNode
|
||||
compileParam: (o) ->
|
||||
name: @name.compile(o)
|
||||
o.scope.find name
|
||||
len: o.scope.freeVariable()
|
||||
o.scope.assign len, "arguments.length"
|
||||
variadic: o.scope.freeVariable()
|
||||
o.scope.assign variadic, "$len >= $@arglength"
|
||||
for trailing, idx in @trailings
|
||||
pos: @trailings.length - idx
|
||||
o.scope.assign(trailing.compile(o), "arguments[$variadic ? $len - $pos : ${@index + idx}]")
|
||||
"$name = ${utility('slice')}.call(arguments, $@index, $len - ${@trailings.length})"
|
||||
end: ''
|
||||
if @trailings.length
|
||||
len: o.scope.freeVariable()
|
||||
o.scope.assign len, "arguments.length"
|
||||
variadic: o.scope.freeVariable()
|
||||
o.scope.assign variadic, "$len >= $@arglength"
|
||||
end: if @trailings.length then ", $len - ${@trailings.length}"
|
||||
for trailing, idx in @trailings
|
||||
pos: @trailings.length - idx
|
||||
o.scope.assign(trailing.compile(o), "arguments[$variadic ? $len - $pos : ${@index + idx}]")
|
||||
"$name = ${utility('slice')}.call(arguments, $@index$end)"
|
||||
|
||||
# A compiling a splat as a destructuring assignment means slicing arguments
|
||||
# from the right-hand-side's corresponding array.
|
||||
|
||||
Reference in New Issue
Block a user