Commit 12c30d22

12c30d221adcMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 5 files · +2 added · ~3 modified

Description

Array literals [1,2,3] now compile to IntArray, ["a","b"] to StrArray

Homogeneous integer array literals produce sp_IntArray instead of sp_RbArray, enabling all IntArray methods (sort, min, max, etc.) without polymorphic boxing. String arrays similarly produce sp_StrArray. Mixed-type arrays still use sp_RbArray as before.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
12c30d221adc
Parent
6bfc4fe5bf20

examples/bm_array_lit.rbaddedView file

1+# Test array literals as IntArray/StrArray
2+
3+# Integer array literal
4+arr = [5, 3, 8, 1, 4]
5+puts arr.length # 5
6+puts arr[0] # 5
7+puts arr.sort[0] # 1
8+puts arr.sum # 21
9+puts arr.min # 1
10+puts arr.max # 8
11+
12+# String array literal
13+words = ["hello", "world", "foo"]
14+puts words.length # 3
15+puts words[0] # hello
16+puts words.join(", ") # hello, world, foo
17+
18+# Empty array
19+empty = []
20+empty.push(42)
21+puts empty.length # 1
22+puts empty[0] # 42
23+
24+puts "done"