Jean Boussier
e85ef212de
[ruby/set] Avoid the block or return pattern to save Proc allocations
Using the block param in a boolean context like this cause it to be
allocated.
Using it with an `if` or `unless` was optimized in 3.2
(https://github.com/ruby/ruby/pull/6286) but using it with `or`
or `and` wasn't.
```ruby
def foo(&block)
block or return 1
end
puts RubyVM::InstructionSequence.of(method(:foo)).disasm
== disasm: #<ISeq:foo@(irb):11 (11,0)-(13,3)> (catch: false)
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: 0, kw: -1@-1, kwrest: -1])
[ 1] block@0<Block>
0000 getblockparam block@0, 0 ( 12)[LiCa]
0003 dup
0004 branchif 10
0006 pop
0007 putobject_INT2FIX_1_
0008 leave [Re]
0009 putnil
0010 leave
```
versus
```
def foo(&block)
return 1 if block
end
puts RubyVM::InstructionSequence.of(method(:foo)).disasm
== disasm: #<ISeq:foo@(irb):15 (15,0)-(17,3)> (catch: false)
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: 0, kw: -1@-1, kwrest: -1])
[ 1] block@0<Block>
0000 getblockparamproxy block@0, 0 ( 16)[LiCa]
0003 branchunless 7
0005 putobject_INT2FIX_1_
0006 leave ( 17)[Re]
0007 putnil ( 16)
0008 leave
```
https://github.com/ruby/set/commit/e89da977d4
2023-01-11 09:26:08 +00:00
..
2022-12-05 05:15:02 +00:00
2023-01-10 15:53:07 +09:00
2022-11-28 04:34:11 +00:00
2022-12-26 15:09:21 +09:00
2022-12-19 14:59:59 +09:00
2022-12-05 05:59:33 +00:00
2022-11-29 04:58:29 +00:00
2022-11-14 06:37:33 +00:00
2023-01-04 09:35:57 +00:00
2022-12-16 06:34:47 +00:00
2023-01-01 15:02:14 +00:00
2022-12-14 05:49:14 +00:00
2022-12-23 09:51:52 +09:00
2022-12-11 18:49:56 +02:00
2022-12-26 15:09:21 +09:00
2023-01-10 12:18:14 +00:00
2022-12-25 22:48:36 -08:00
2023-01-10 15:53:07 +09:00
2022-12-20 14:50:08 +09:00
2022-12-06 10:11:33 +09:00
2023-01-08 23:14:50 +00:00
2022-12-09 16:36:22 +09:00
2022-12-14 07:38:37 +00:00
2023-01-10 15:53:07 +09:00
2022-11-28 04:40:26 +00:00
2022-12-09 16:36:22 +09:00
2022-12-05 05:47:54 +00:00
2023-01-07 08:47:05 +00:00
2022-12-14 07:53:51 +00:00
2022-12-26 12:07:42 +09:00
2022-11-24 23:40:53 +00:00
2022-12-05 06:12:31 +00:00
2022-12-05 06:15:38 +00:00
2022-12-05 06:19:25 +00:00
2022-12-05 06:32:03 +00:00
2022-11-21 08:46:27 +00:00
2022-10-12 12:27:40 +09:00
2023-01-09 21:44:15 +09:00
2022-12-05 06:39:55 +00:00
2022-12-05 07:14:06 +00:00
2022-10-12 10:36:51 +09:00
2022-12-26 15:09:21 +09:00
2022-12-05 07:35:19 +00:00
2022-10-14 21:31:24 +09:00
2022-12-05 07:38:23 +00:00
2022-12-05 03:14:55 +00:00
2022-12-14 17:42:15 +09:00
2022-12-05 07:49:03 +00:00
2023-01-10 15:53:07 +09:00
2022-12-14 08:48:38 +00:00
2023-01-11 09:26:08 +00:00
2022-12-14 05:35:48 +00:00
2022-10-12 12:27:40 +09:00
2022-12-14 16:07:44 +09:00
2022-12-05 08:13:18 +00:00
2022-12-05 08:15:11 +00:00
2022-10-25 07:54:40 +00:00
2022-12-05 08:16:29 +00:00
2022-12-05 08:18:33 +00:00
2022-11-30 10:09:17 +00:00
2022-12-14 06:16:29 +00:00