@@ -818,6 +818,8 @@ protected Object sliceCapture(VirtualFrame frame, Object string, RubyRegexp rege
818
818
@ Cached ReadCallerVariablesNode readCallerStorageNode ,
819
819
@ Cached ConditionProfile unsetProfile ,
820
820
@ Cached ConditionProfile sameThreadProfile ,
821
+ @ Cached ConditionProfile notMatchedProfile ,
822
+ @ Cached ConditionProfile captureSetProfile ,
821
823
@ Cached StringDupAsStringInstanceNode dupNode ) {
822
824
final Object capture = RubyGuards .wasProvided (maybeCapture ) ? maybeCapture : 0 ;
823
825
final Object matchStrPair = callNode .call (
@@ -828,13 +830,19 @@ protected Object sliceCapture(VirtualFrame frame, Object string, RubyRegexp rege
828
830
capture );
829
831
830
832
final SpecialVariableStorage variables = readCallerStorageNode .execute (frame );
831
- if (matchStrPair == nil ) {
833
+ if (notMatchedProfile . profile ( matchStrPair == nil ) ) {
832
834
variables .setLastMatch (nil , getContext (), unsetProfile , sameThreadProfile );
833
835
return nil ;
834
836
} else {
835
837
final Object [] array = (Object []) ((RubyArray ) matchStrPair ).store ;
836
- variables .setLastMatch (array [0 ], getContext (), unsetProfile , sameThreadProfile );
837
- return dupNode .executeDupAsStringInstance (array [1 ]);
838
+ final Object matchData = array [0 ];
839
+ final Object captureStringOrNil = array [1 ];
840
+ variables .setLastMatch (matchData , getContext (), unsetProfile , sameThreadProfile );
841
+ if (captureSetProfile .profile (captureStringOrNil != nil )) {
842
+ return dupNode .executeDupAsStringInstance (captureStringOrNil );
843
+ } else {
844
+ return nil ;
845
+ }
838
846
}
839
847
}
840
848
0 commit comments