Revert moving things to Ruby

This is slowing down benchmarks on x86, so lets revert it for now.
This commit is contained in:
Aaron Patterson 2024-07-29 13:28:57 -07:00 committed by Aaron Patterson
parent acbb8d4fb5
commit 2c1655314a
Notes: git 2024-07-29 21:18:29 +00:00
6 changed files with 128 additions and 113 deletions

View file

@ -55,73 +55,6 @@ class Array
self
end
# call-seq:
# array.map {|element| ... } -> new_array
# array.map -> new_enumerator
#
# Calls the block, if given, with each element of +self+;
# returns a new +Array+ whose elements are the return values from the block:
#
# a = [:foo, 'bar', 2]
# a1 = a.map {|element| element.class }
# a1 # => [Symbol, String, Integer]
#
# Returns a new Enumerator if no block given:
# a = [:foo, 'bar', 2]
# a1 = a.map
# a1 # => #<Enumerator: [:foo, "bar", 2]:map>
def map
Primitive.attr! :inline_block
unless defined?(yield)
return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 0, 0, ary_enum_length)'
end
_i = 0
value = nil
result = Primitive.ary_sized_alloc
while Primitive.cexpr!(%q{ ary_fetch_next(self, LOCAL_PTR(_i), LOCAL_PTR(value)) })
result << yield(value)
end
result
end
alias collect map
# call-seq:
# array.select {|element| ... } -> new_array
# array.select -> new_enumerator
#
# Calls the block, if given, with each element of +self+;
# returns a new +Array+ containing those elements of +self+
# for which the block returns a truthy value:
#
# a = [:foo, 'bar', 2, :bam]
# a1 = a.select {|element| element.to_s.start_with?('b') }
# a1 # => ["bar", :bam]
#
# Returns a new Enumerator if no block given:
#
# a = [:foo, 'bar', 2, :bam]
# a.select # => #<Enumerator: [:foo, "bar", 2, :bam]:select>
def select
Primitive.attr! :inline_block
unless defined?(yield)
return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 0, 0, ary_enum_length)'
end
_i = 0
value = nil
result = Primitive.ary_sized_alloc
while Primitive.cexpr!(%q{ ary_fetch_next(self, LOCAL_PTR(_i), LOCAL_PTR(value)) })
result << value if yield value
end
result
end
alias filter select
# call-seq:
# array.shuffle!(random: Random) -> array
#