Hi,
In message "Re: [ruby-core:17381] Re: A faster Array#delete"
on Tue, 24 Jun 2008 00:15:47 +0900, "Berger, Daniel" <Daniel.Berger / qwest.com> writes:
|>Besides that, it
|> doesn't work well (out of bound access) if the comparing
|> method alters (e.g. shorten) the receiver.
|
|Can you give us some examples? They would be useful test cases.
Your version would have access violation with the following program.
matz.
---
require 'benchmark'
class Foo
def ==(other)
$array.clear
false
end
end
MAX = 30000
array = ['daniel'] * 1000
array << ['charles'] * 1000
array << ['matz'] * 1000
array << 'larry'
array << Foo.new
array << ['larry'] * 1000
array << ['guido'] * 1000
array.flatten!
$array = array
Benchmark.bm(10) do |x|
x.report("delete"){
MAX.times{ array.delete('larry') }
}
p array.size
end