Skip to content

Commit

Permalink
Fix Array#delete for 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Mar 24, 2013
1 parent f0fcc54 commit b93a814
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 32 deletions.
31 changes: 0 additions & 31 deletions kernel/common/array.rb
Expand Up @@ -373,37 +373,6 @@ def cycle(n=nil, &block)
nil
end

def delete(obj)
key = undefined
i = @start
total = i + @total
tuple = @tuple

while i < total
if tuple.at(i) == obj
# We MUST check frozen here, not at the top, because MRI
# requires that #delete not raise unless an element would
# be deleted.
Rubinius.check_frozen
tuple.put i, key
end
i += 1
end

deleted = @tuple.delete @start, @total, key
if deleted > 0
@total -= deleted
reallocate_shrink()
return obj
end

if block_given?
yield
else
nil
end
end

def delete_at(idx)
Rubinius.check_frozen

Expand Down
31 changes: 31 additions & 0 deletions kernel/common/array18.rb
Expand Up @@ -238,6 +238,37 @@ def concat(other)
concat other
end

def delete(obj)
key = undefined
i = @start
total = i + @total
tuple = @tuple

while i < total
if tuple.at(i) == obj
# We MUST check frozen here, not at the top, because MRI
# requires that #delete not raise unless an element would
# be deleted.
Rubinius.check_frozen
tuple.put i, key
end
i += 1
end

deleted = @tuple.delete @start, @total, key
if deleted > 0
@total -= deleted
reallocate_shrink()
return obj
end

if block_given?
yield
else
nil
end
end

def flatten(level=-1)
level = Rubinius::Type.coerce_to(level, Integer, :to_int)
return self if level == 0
Expand Down
33 changes: 33 additions & 0 deletions kernel/common/array19.rb
Expand Up @@ -204,6 +204,39 @@ def concat(other)
concat other
end

def delete(obj)
key = undefined
i = @start
total = i + @total
tuple = @tuple

while i < total
element = tuple.at i
if element == obj
# We MUST check frozen here, not at the top, because MRI
# requires that #delete not raise unless an element would
# be deleted.
Rubinius.check_frozen
tuple.put i, key
last_matched_element = element
end
i += 1
end

deleted = @tuple.delete @start, @total, key
if deleted > 0
@total -= deleted
reallocate_shrink()
return last_matched_element
end

if block_given?
yield
else
nil
end
end

def flatten(level=-1)
level = Rubinius::Type.coerce_to(level, Integer, :to_int)
return self.dup if level == 0
Expand Down
1 change: 0 additions & 1 deletion spec/tags/19/ruby/core/array/delete_tags.txt

This file was deleted.

0 comments on commit b93a814

Please sign in to comment.