File tree Expand file tree Collapse file tree 1 file changed +9
-18
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 1 file changed +9
-18
lines changed Original file line number Diff line number Diff line change @@ -391,26 +391,17 @@ def reject
391
391
end
392
392
393
393
def grep ( pattern , &block )
394
- if block_given?
395
- Lazy . new ( self , nil ) do |yielder , *args |
396
- val = args . length >= 2 ? args : args . first
397
- matches = pattern === val
398
- Truffle ::RegexpOperations . set_last_match ( $~, block . binding )
399
-
400
- if matches
401
- yielder . yield yield ( val )
402
- end
403
- end
404
- else
405
- # :caller_binding is not optimized in blocks right now, and we want the caller of #grep
406
- caller_binding = Truffle . invoke_primitive ( :caller_binding )
394
+ binding = block ? block . binding : Truffle . invoke_primitive ( :caller_binding )
407
395
408
- Lazy . new ( self , nil ) do |yielder , *args |
409
- val = args . length >= 2 ? args : args . first
410
- matches = pattern === val
411
- Truffle ::RegexpOperations . set_last_match ( $~, caller_binding )
396
+ Lazy . new ( self , nil ) do |yielder , *args |
397
+ val = args . length >= 2 ? args : args . first
398
+ matches = pattern === val
399
+ Truffle ::RegexpOperations . set_last_match ( $~, binding )
412
400
413
- if matches
401
+ if matches
402
+ if block
403
+ yielder . yield yield ( val )
404
+ else
414
405
yielder . yield val
415
406
end
416
407
end
You can’t perform that action at this time.
0 commit comments