Issue #6668 has been reported by headius (Charles Nutter).
Author: headius (Charles Nutter)
Currently, when doing multiple assignment, the entire expression must return the right-hand side as an array.
system ~ $ ruby -e "ret = (a, b, c = 1, 2, 3); p ret"
[1, 2, 3]
This is an artifact of MRI's implementation, since multiple assignment was traditionally implemented by taking the array node on the right-hand side, standing it up as a full Ruby Array, and then peeling elements off for assignment on the left-hand side. It is also a performance issue, since it requires constructing the RHS array even when it is never used (unless you are able to do various compiler tricks). I propose removing it.
* The feature is rarely used; most people don't even know it exists.
* The impact of creating the RHS array is significant; JRuby can optimize it away in cases where the line is not used as an expression, and the performance difference is huge: <a href="https://gist.github.com/3019255" title="https://gist.github.com/3019255">https://gist.github.com/3019255</a>
* It is counter-intuitive to have an automatic performance hit just from grouping assignments. "a,b = 1,2" should have the exact same performance as "a = 1; b = 2"
Note that while JRuby can eliminate the array creation in non-expression cases, those are somewhat rare since many times masgn is used at the end of a method body, as for initializers:
def initialize(a, b, c)
@a, @b, @c = a, b, c
JRuby and other implementations may get smart enough in our optimizers to eliminate the array in all cases where it's not needed, but this is a very large burden on the optimization subsystem. It may also not be possible to do in all cases (or not possible to do in even a majority of cases).
Multiple assignment should not return RHS as an array. I do not care what it returns.
|[ruby-trunk - Bug #5759][Open] flatten calls to_ary on everything||7|
|[ruby-trunk - Bug #7133][Open] [mingw] bogus TestProcess#test_execopts_gid test failure||0|
|[CommonRuby - Feature #8272][Open] Transfer feature tracking to CommonRuby||0|
|[ruby-trunk - Bug #6945][Open] URI::parse throws NoMethodError on some ftp-URIs||0|
|[Ruby 1.9 - Feature #5444][Open] Object.free||3|
|[ruby-trunk - Bug #5946][Open] Remove too early and unnecessary calls to heaps_increment||3|
|[ruby-trunk - Bug #5813][Assigned] net/http's EOFError and Keep-Alive||0|
|[ruby-trunk - Bug #6374][Open] Acces to initialized class variable from included module||6|
|[Ruby 1.9 - Bug #4735][Open] lib/scanf.rb Documentation Improvement||1|