Project

General

Profile

Bug #5752

Array#delete_if side effects due to changeset r32360

Added by gettalong (Thomas Leitner) about 7 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
Backport:
[ruby-core:41616]

Description

It seems that the changeset r32360 introduced another side effect. Here are two IRB sessions, one in ruby-1.9.2-p136 and the other in ruby-1.9.3-p0:

ruby-1.9.2-p136 :001 > x = [1,2,3,4,5,6,7,8,9]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
ruby-1.9.2-p136 :002 > x.delete_if {|i| i == x[i-1]}
=> []

ruby-1.9.3-p0 :001 > x = [1,2,3,4,5,6,7,8,9]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
ruby-1.9.3-p0 :002 > x.delete_if {|i| i == x[i-1]}
=> [2, 3, 4, 5, 6, 7, 8, 9]

If this is indeed the intended behaviour, it should probably be documented clearly that the array is changed instantly every time the block is called and not after the iteration is over.


Files

array.c.patch (719 Bytes) array.c.patch fix delete_if funny_falcon (Yura Sokolov), 12/14/2011 07:03 PM

Related issues

Related to Ruby trunk - Feature #10714: Array#reject! nonlinear performance problemClosed01/08/2015Actions

Associated revisions

Revision 58b5838d
Added by nobu (Nobuyoshi Nakada) about 7 years ago

  • array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc. documentation from Thomas Leitner in [ruby-core:41616]. [Bug #5752]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34048 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 15f26afd
Added by nobu (Nobuyoshi Nakada) about 7 years ago

  • array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc. documentation from Thomas Leitner in [ruby-core:41616]. [Bug #5752]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34048 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 34048
Added by nobu (Nobuyoshi Nakada) about 7 years ago

  • array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc. documentation from Thomas Leitner in [ruby-core:41616]. [Bug #5752]

Revision 34048
Added by nobu (Nobuyoshi Nakada) about 7 years ago

  • array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc. documentation from Thomas Leitner in [ruby-core:41616]. [Bug #5752]

Revision 34048
Added by nobu (Nobuyoshi Nakada) about 7 years ago

  • array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc. documentation from Thomas Leitner in [ruby-core:41616]. [Bug #5752]

Revision 34048
Added by nobu (Nobuyoshi Nakada) about 7 years ago

  • array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc. documentation from Thomas Leitner in [ruby-core:41616]. [Bug #5752]

Revision 34048
Added by nobu (Nobuyoshi Nakada) about 7 years ago

  • array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc. documentation from Thomas Leitner in [ruby-core:41616]. [Bug #5752]

Revision 34048
Added by nobu (Nobuyoshi Nakada) about 7 years ago

  • array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc. documentation from Thomas Leitner in [ruby-core:41616]. [Bug #5752]

History

Updated by funny_falcon (Yura Sokolov) about 7 years ago

Actually, it were next changeset r32373

Updated by nobu (Nobuyoshi Nakada) about 7 years ago

  • Category changed from core to doc
  • Status changed from Open to Closed

Updated by akr (Akira Tanaka) about 4 years ago

  • Related to Feature #10714: Array#reject! nonlinear performance problem added

Also available in: Atom PDF