summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <[email protected]>2024-07-29 13:28:57 -0700
committerAaron Patterson <[email protected]>2024-07-29 14:18:11 -0700
commit2c1655314a0700a90b7ed12bf8c920ad2d78654f ()
treeec758c9e97cc71adf644b85a622c279766ad8646
parentacbb8d4fb56ac3b5894991760a075dbef78d10e3 (diff)
Revert moving things to Ruby
This is slowing down benchmarks on x86, so lets revert it for now.
Notes: Merged: https://.com/ruby/ruby/pull/11275
-rw-r--r--array.c81
-rw-r--r--array.rb67
-rw-r--r--numeric.c45
-rw-r--r--numeric.rb30
-rw-r--r--test/ruby/test_backtrace.rb6
-rw-r--r--test/ruby/test_settracefunc.rb12
6 files changed, 128 insertions, 113 deletions
@@ -3630,6 +3630,41 @@ rb_ary_sort_by_bang(VALUE ary)
return ary;
}
/*
* call-seq:
* array.map! {|element| ... } -> self
@@ -3772,6 +3807,42 @@ rb_ary_values_at(int argc, VALUE *argv, VALUE ary)
}
struct select_bang_arg {
VALUE ary;
long len[2];
@@ -6626,12 +6697,6 @@ ary_sample(rb_execution_context_t *ec, VALUE ary, VALUE randgen, VALUE nv, VALUE
}
static VALUE
-ary_sized_alloc(rb_execution_context_t *ec, VALUE self)
-{
- return rb_ary_new2(RARRAY_LEN(self));
-}
-
-static VALUE
ary_sample0(rb_execution_context_t *ec, VALUE ary)
{
return ary_sample(ec, ary, rb_cRandom, Qfalse, Qfalse);
@@ -8633,9 +8698,13 @@ Init_Array(void)
rb_define_method(rb_cArray, "sort", rb_ary_sort, 0);
rb_define_method(rb_cArray, "sort!", rb_ary_sort_bang, 0);
rb_define_method(rb_cArray, "sort_by!", rb_ary_sort_by_bang, 0);
rb_define_method(rb_cArray, "collect!", rb_ary_collect_bang, 0);
rb_define_method(rb_cArray, "map!", rb_ary_collect_bang, 0);
rb_define_method(rb_cArray, "select!", rb_ary_select_bang, 0);
rb_define_method(rb_cArray, "filter!", rb_ary_select_bang, 0);
rb_define_method(rb_cArray, "keep_if", rb_ary_keep_if, 0);
rb_define_method(rb_cArray, "values_at", rb_ary_values_at, -1);
@@ -56,73 +56,6 @@ class Array
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
#
# Shuffles the elements of +self+ in place.
@@ -5713,6 +5713,50 @@ int_downto_size(VALUE from, VALUE args, VALUE eobj)
return ruby_num_interval_step_size(from, RARRAY_AREF(args, 0), INT2FIX(-1), FALSE);
}
static VALUE
int_dotimes_size(VALUE num, VALUE args, VALUE eobj)
{
@@ -6320,6 +6364,7 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "anybits?", int_anybits_p, 1);
rb_define_method(rb_cInteger, "nobits?", int_nobits_p, 1);
rb_define_method(rb_cInteger, "upto", int_upto, 1);
rb_define_method(rb_cInteger, "succ", int_succ, 0);
rb_define_method(rb_cInteger, "next", int_succ, 0);
rb_define_method(rb_cInteger, "pred", int_pred, 0);
@@ -241,36 +241,6 @@ class Integer
self
end
- # call-seq:
- # downto(limit) {|i| ... } -> self
- # downto(limit) -> enumerator
- #
- # Calls the given block with each integer value from +self+ down to +limit+;
- # returns +self+:
- #
- # a = []
- # 10.downto(5) {|i| a << i } # => 10
- # a # => [10, 9, 8, 7, 6, 5]
- # a = []
- # 0.downto(-5) {|i| a << i } # => 0
- # a # => [0, -1, -2, -3, -4, -5]
- # 4.downto(5) {|i| fail 'Cannot happen' } # => 4
- #
- # With no block given, returns an Enumerator.
- def downto to
- Primitive.attr! :inline_block
- unless defined?(yield)
- return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 1, &to, int_downto_size)'
- end
-
- from = self
- while from >= to
- yield from
- from = from.pred
- end
- self
- end
-
# call-seq:
# to_i -> self
#
@@ -223,15 +223,15 @@ class TestBacktrace < Test::Unit::TestCase
@res = caller_locations(2, 1).inspect
end
@line = __LINE__ + 1
- [1].map!.map { [1].map!.map { foo } }
- assert_equal("[\"#{__FILE__}:#{@line}:in 'Array#map!'\"]", @res)
end
def test_caller_location_path_cfunc_iseq_no_pc
def self.foo
@res = caller_locations(2, 1)[0].path
end
- [1].map!.map { [1].map!.map { foo } }
assert_equal(__FILE__, @res)
end
@@ -680,8 +680,10 @@ CODE
#
[:c_return, 1, "xyzzy", TracePoint, :trace, TracePoint, nil, nil],
[:line, 4, 'xyzzy', self.class, method, self, :outer, :nothing],
[:line, 4, 'xyzzy', self.class, method, self, nil, :nothing],
[:line, 5, 'xyzzy', self.class, method, self, :inner, :nothing],
[:line, 7, 'xyzzy', self.class, method, self, :outer, :nothing],
[:c_call, 7, "xyzzy", Class, :inherited, Object, nil, nil],
[:c_return, 7, "xyzzy", Class, :inherited, Object, nil, nil],
@@ -1067,12 +1069,10 @@ CODE
# pp events
# expected_events =
[[:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil],
- [:call, :map, Array, Array, nil],
[:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil],
[:b_return, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, 3],
- [:c_call, :<<, Array, Array, nil],
- [:c_return, :<<, Array, Array, [3]],
- [:return, :map, Array, Array, [3]],
[:call, :method_for_test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil],
[:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil],
[:b_return, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, 4],
@@ -1388,9 +1388,8 @@ CODE
}
assert_equal([
:b_call,
- :call,
- :b_call,
:c_call,
:call,
:b_call,
], events, "TracePoint log:\n#{ log.join("\n") }\n")
@@ -1414,7 +1413,6 @@ CODE
assert_equal([
:b_return,
:c_return,
- :return,
:b_return,
:return,
:b_return