[ruby-dev:48808] [ruby-trunk - Bug #10722] Array#keep_if is borked if user calls 'break'
From:
akr@...
Date:
2015-01-10 04:08:04 UTC
List:
ruby-dev #48808
Issue #10722 has been updated by Akira Tanaka.
r49196 causes nonlinear performance problem.
```
% ./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]
```
----------------------------------------
Bug #10722: Array#keep_if is borked if user calls 'break'
https://bugs.ruby-lang.org/issues/10722#change-50902
* Author: _ wanabe
* Status: Closed
* Priority: Normal
* Assignee:
* Category:
* Target version:
* ruby -v: ruby 2.3.0dev (2015-01-09 trunk 49192) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
ref. [Bug #2545]
```
$ ruby -e 'a = [5,6,7,8,9,10]; a.keep_if { |x| break if x > 8; x >= 7 }; p a'
[7, 8, 7, 8, 9, 10]
$ ruby -e 'a = [5,6,7,8,9,10]; a.delete_if { |x| break if x > 8; x < 7 }; p a'
[7, 8, 9, 10]
```
I was expecting the above scripts to be same results.
--
https://bugs.ruby-lang.org/