https://bugs.ruby-lang.org/
https://bugs.ruby-lang.org/favicon.ico?1711330511
2015-01-09T08:53:15Z
Ruby Issue Tracking System
Ruby master - Bug #10722: Array#keep_if is borked if user calls 'break'
https://bugs.ruby-lang.org/issues/10722?journal_id=50880
2015-01-09T08:53:15Z
wanabe (_ wanabe)
s.wanabe@gmail.com
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/2545">Bug #2545</a>: Array#delete_if is borked if user calls 'break'</i> added</li></ul>
Ruby master - Bug #10722: Array#keep_if is borked if user calls 'break'
https://bugs.ruby-lang.org/issues/10722?journal_id=50890
2015-01-10T01:12:33Z
nobu (Nobuyoshi Nakada)
nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>Applied in changeset r49196.</p>
<hr>
<p>array.c: keep consistency</p>
<ul>
<li>array.c (rb_ary_select_bang): keep the array consistent by<br>
removing unselected values soon. <a href="/issues/10722">[ruby-dev:48805]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Array#keep_if is borked if user calls 'break' (Closed)" href="https://bugs.ruby-lang.org/issues/10722">#10722</a>]</li>
</ul>
Ruby master - Bug #10722: Array#keep_if is borked if user calls 'break'
https://bugs.ruby-lang.org/issues/10722?journal_id=50902
2015-01-10T04:08:04Z
akr (Akira Tanaka)
akr@fsij.org
<ul></ul><p>r49196 causes nonlinear performance problem.</p>
<pre><code>% ./ruby -v -e '
20.times {|i|
a = [nil]*i*10000;
t1 = Time.now
a.keep_if { false }
t2 = Time.now
t = t2 - t1
p ["*" * (t * 20).to_i , t]
}
'
ruby 2.3.0dev (2015-01-10 trunk 49203) [x86_64-linux]
["", 2.229e-06]
["", 0.01375934]
["*", 0.052734738]
["**", 0.117660945]
["****", 0.209578563]
["******", 0.33836772]
["*********", 0.48799636]
["*************", 0.662050118]
["*****************", 0.876530968]
["**********************", 1.12094001]
["****************************", 1.402435918]
["**********************************", 1.709450864]
["*******************************************", 2.163054065]
["*************************************************", 2.480529295]
["************************************************************", 3.010499657]
["**********************************************************************", 3.535099527]
["***************************************************************************************", 4.389055292]
["*****************************************************************************************************", 5.053431719]
["*******************************************************************************************************", 5.190555455]
["***************************************************************************************************************", 5.59821402]
</code></pre>
Ruby master - Bug #10722: Array#keep_if is borked if user calls 'break'
https://bugs.ruby-lang.org/issues/10722?journal_id=50911
2015-01-10T07:54:20Z
akr (Akira Tanaka)
akr@fsij.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/10714">Feature #10714</a>: Array#reject! nonlinear performance problem</i> added</li></ul>
Ruby master - Bug #10722: Array#keep_if is borked if user calls 'break'
https://bugs.ruby-lang.org/issues/10722?journal_id=50919
2015-01-10T13:47:12Z
akr (Akira Tanaka)
akr@fsij.org
<ul></ul><p>Apart from the performance problem, I feel following exmaple should show [7,8].</p>
<pre><code>a = [5,6,7,8,9,10]; a.keep_if { |x| break if x > 8; x >= 7 }; p a
</code></pre>
<p>Because the method name is "keep_if", the method should keep only elements which the block returns true.<br>
The block doesn't return true since "break" for 9 and 10.<br>
So they should not be keeped.</p>
<p>This is similar (but reversed) to nagachika's comment for delete_if:<br>
<a href="https://bugs.ruby-lang.org/issues/2545#note-6" class="external">https://bugs.ruby-lang.org/issues/2545#note-6</a></p>
Ruby master - Bug #10722: Array#keep_if is borked if user calls 'break'
https://bugs.ruby-lang.org/issues/10722?journal_id=51017
2015-01-15T02:02:48Z
akr (Akira Tanaka)
akr@fsij.org
<ul></ul><p>r49255 fixes the performance problem.</p>