[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Why does Array#first not use rb_ary_subseq?

Stefan Rusterholz

5/18/2007 12:36:00 PM

Hi there

When I run a small bench I noticed that Array#first(n) with an argument
is vastly slower than Array#[0,n].
Poking a bit in the source revealed that Array#[] uses rb_ary_subseq,
which seems to create a COW Array while Array#first creates a new Array
on its own and fills it with values. Is there any rationale as to why
Array#first doesn't just use rb_ary_subseq too?
I searched the ML for an answer to this and found none. Forgive me
please if I overlooked the answer.

Regards
Stefan Rusterholz

--
Posted via http://www.ruby-....