File tree Expand file tree Collapse file tree 2 files changed +12
-13
lines changed
spec/tags/core/enumerator/lazy
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 2 files changed +12
-13
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -394,24 +394,26 @@ def grep(pattern, &block)
394
394
if block_given?
395
395
Lazy . new ( self , nil ) do |yielder , *args |
396
396
val = args . length >= 2 ? args : args . first
397
- if pattern === val
398
- Truffle ::RegexpOperations . set_last_match ( $~, block . binding )
397
+ matches = pattern === val
398
+ Truffle ::RegexpOperations . set_last_match ( $~, block . binding )
399
+
400
+ if matches
399
401
yielder . yield yield ( val )
400
402
end
401
403
end
402
404
else
403
- lazy = Lazy . new ( self , nil ) do |yielder , *args |
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 )
407
+
408
+ Lazy . new ( self , nil ) do |yielder , *args |
404
409
val = args . length >= 2 ? args : args . first
405
- if pattern === val
410
+ matches = pattern === val
411
+ Truffle ::RegexpOperations . set_last_match ( $~, caller_binding )
412
+
413
+ if matches
406
414
yielder . yield val
407
415
end
408
-
409
- Truffle ::RegexpOperations . set_last_match ( $~, Truffle . invoke_primitive ( :caller_binding ) )
410
416
end
411
-
412
- Truffle ::RegexpOperations . set_last_match ( $~, Truffle . invoke_primitive ( :caller_binding ) )
413
-
414
- lazy
415
417
end
416
418
end
417
419
You can’t perform that action at this time.
0 commit comments