mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
optimizing the output of compiled splat arguments.
This commit is contained in:
@@ -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