Commit f93ef19f
f93ef19f8f26Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Add Array#sort, #min, #max, #sum, #reduce/#inject
- sort → sp_IntArray_sort (qsort-based copy)
- sort! → sp_IntArray_sort_bang (in-place qsort)
- min/max → inline loop
- sum → inline accumulator loop
- reduce(init) { |acc, x| expr } → inline fold with temp var Block params registered in var table for proper type inference.
Test: examples/bm_sort_reduce.rb — all patterns match Ruby.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- f93ef19f8f26
- Parent
- 32ab2ae8eabe
examples/bm_sort_reduce.rbaddedView file
1+
# Test Array#sort, reduce, min, max, sum2+
3+
arr = (1..10).to_a4+
arr.reverse!5+
6+
# sort7+
sorted = arr.sort8+
puts sorted.first # 19+
puts sorted.last # 1010+
11+
# min/max/sum12+
puts arr.min # 113+
puts arr.max # 1014+
puts arr.sum # 5515+
16+
# reduce17+
puts arr.reduce(0) { |sum, x| sum + x } # 5518+
puts arr.reduce(1) { |prod, x| prod * x } # 362880019+
20+
# inject (alias)21+
puts arr.inject(0) { |s, x| s + x } # 55src/codegen.cmodifiedView file
Loading diff…