22
22
import com .oracle .truffle .api .profiles .InlinedLoopConditionProfile ;
23
23
import com .oracle .truffle .api .strings .AbstractTruffleString ;
24
24
import com .oracle .truffle .api .strings .TruffleString ;
25
+ import org .graalvm .shadowed .org .joni .MultiRegion ;
25
26
import org .graalvm .shadowed .org .joni .NameEntry ;
26
27
import org .graalvm .shadowed .org .joni .Regex ;
27
- import org .graalvm .shadowed .org .joni .Region ;
28
28
import org .graalvm .shadowed .org .joni .exception .ValueException ;
29
29
import org .truffleruby .annotations .CoreMethod ;
30
30
import org .truffleruby .builtins .CoreMethodArrayArgumentsNode ;
@@ -78,46 +78,46 @@ private static int getGroupBound(InteropLibrary interop, RubyMatchData matchData
78
78
79
79
private static int getStart (Node node , RubyMatchData matchData , int index , InlinedConditionProfile lazyProfile ,
80
80
InteropLibrary interop ) {
81
- int start = matchData .region .beg [ index ] ;
81
+ int start = matchData .region .getBeg ( index ) ;
82
82
if (lazyProfile .profile (node , start == RubyMatchData .LAZY )) {
83
- return matchData .region .beg [ index ] = getGroupBound (interop , matchData , "getStart" , index );
83
+ return matchData .region .setBeg ( index , getGroupBound (interop , matchData , "getStart" , index ) );
84
84
} else {
85
85
return start ;
86
86
}
87
87
}
88
88
89
89
private static int getEnd (Node node , RubyMatchData matchData , int index , InlinedConditionProfile lazyProfile ,
90
90
InteropLibrary interop ) {
91
- int end = matchData .region .end [ index ] ;
91
+ int end = matchData .region .getEnd ( index ) ;
92
92
if (lazyProfile .profile (node , end == RubyMatchData .LAZY )) {
93
- return matchData .region .end [ index ] = getGroupBound (interop , matchData , "getEnd" , index );
93
+ return matchData .region .setEnd ( index , getGroupBound (interop , matchData , "getEnd" , index ) );
94
94
} else {
95
95
return end ;
96
96
}
97
97
}
98
98
99
99
private static void forceLazyMatchData (RubyMatchData matchData , InteropLibrary interop ) {
100
- for (int i = 0 ; i < matchData .region .numRegs ; i ++) {
100
+ for (int i = 0 ; i < matchData .region .getNumRegs () ; i ++) {
101
101
getStart (null , matchData , i , InlinedConditionProfile .getUncached (), interop );
102
102
getEnd (null , matchData , i , InlinedConditionProfile .getUncached (), interop );
103
103
}
104
104
}
105
105
106
106
@ TruffleBoundary
107
- private static Region getCharOffsetsManyRegs (RubyMatchData matchData , AbstractTruffleString source ,
107
+ private static MultiRegion getCharOffsetsManyRegs (RubyMatchData matchData , AbstractTruffleString source ,
108
108
RubyEncoding encoding ) {
109
109
// Taken from org.jruby.RubyMatchData
110
110
111
111
assert !encoding .isSingleByte : "Should be checked by callers" ;
112
112
113
- final Region regs = matchData .region ;
114
- int numRegs = regs .numRegs ;
113
+ final MultiRegion regs = matchData .region ;
114
+ int numRegs = regs .getNumRegs () ;
115
115
116
116
if (matchData .tRegexResult != null ) {
117
117
forceLazyMatchData (matchData , InteropLibrary .getUncached (matchData .tRegexResult ));
118
118
}
119
119
120
- final Region charOffsets = new Region (numRegs );
120
+ final MultiRegion charOffsets = new MultiRegion (numRegs );
121
121
122
122
final Pair [] pairs = new Pair [numRegs * 2 ];
123
123
for (int i = 0 ; i < pairs .length ; i ++) {
@@ -126,23 +126,24 @@ private static Region getCharOffsetsManyRegs(RubyMatchData matchData, AbstractTr
126
126
127
127
int numPos = 0 ;
128
128
for (int i = 0 ; i < numRegs ; i ++) {
129
- if (regs .beg [ i ] != RubyMatchData .MISSING ) {
130
- pairs [numPos ++].bytePos = regs .beg [ i ] ;
131
- pairs [numPos ++].bytePos = regs .end [ i ] ;
129
+ if (regs .getBeg ( i ) != RubyMatchData .MISSING ) {
130
+ pairs [numPos ++].bytePos = regs .getBeg ( i ) ;
131
+ pairs [numPos ++].bytePos = regs .getEnd ( i ) ;
132
132
}
133
133
}
134
134
135
135
updatePairs (source , encoding , pairs );
136
136
137
137
Pair key = new Pair ();
138
- for (int i = 0 ; i < regs .numRegs ; i ++) {
139
- if (regs .beg [i ] == RubyMatchData .MISSING ) {
140
- charOffsets .beg [i ] = charOffsets .end [i ] = RubyMatchData .MISSING ;
138
+ for (int i = 0 ; i < regs .getNumRegs (); i ++) {
139
+ if (regs .getBeg (i ) == RubyMatchData .MISSING ) {
140
+ charOffsets .setBeg (i , RubyMatchData .MISSING );
141
+ charOffsets .setEnd (i , RubyMatchData .MISSING );
141
142
} else {
142
- key .bytePos = regs .beg [ i ] ;
143
- charOffsets .beg [ i ] = pairs [Arrays .binarySearch (pairs , key )].charPos ;
144
- key .bytePos = regs .end [ i ] ;
145
- charOffsets .end [ i ] = pairs [Arrays .binarySearch (pairs , key )].charPos ;
143
+ key .bytePos = regs .getBeg ( i ) ;
144
+ charOffsets .setBeg ( i , pairs [Arrays .binarySearch (pairs , key )].charPos ) ;
145
+ key .bytePos = regs .getEnd ( i ) ;
146
+ charOffsets .setEnd ( i , pairs [Arrays .binarySearch (pairs , key )].charPos ) ;
146
147
}
147
148
}
148
149
@@ -169,15 +170,16 @@ private static void updatePairs(AbstractTruffleString source, RubyEncoding encod
169
170
}
170
171
171
172
@ TruffleBoundary
172
- private static Region createCharOffsets (RubyMatchData matchData , AbstractTruffleString source ,
173
+ private static MultiRegion createCharOffsets (RubyMatchData matchData , AbstractTruffleString source ,
173
174
RubyEncoding encoding ) {
174
- final Region charOffsets = getCharOffsetsManyRegs (matchData , source , encoding );
175
+ final MultiRegion charOffsets = getCharOffsetsManyRegs (matchData , source , encoding );
175
176
matchData .charOffsets = charOffsets ;
176
177
return charOffsets ;
177
178
}
178
179
179
- private static Region getCharOffsets (RubyMatchData matchData , AbstractTruffleString source , RubyEncoding encoding ) {
180
- final Region charOffsets = matchData .charOffsets ;
180
+ private static MultiRegion getCharOffsets (RubyMatchData matchData , AbstractTruffleString source ,
181
+ RubyEncoding encoding ) {
182
+ final MultiRegion charOffsets = matchData .charOffsets ;
181
183
if (charOffsets != null ) {
182
184
return charOffsets ;
183
185
} else {
@@ -188,13 +190,13 @@ private static Region getCharOffsets(RubyMatchData matchData, AbstractTruffleStr
188
190
@ TruffleBoundary
189
191
private static void fixupMatchDataForStart (RubyMatchData matchData , int startPos ) {
190
192
assert startPos != 0 ;
191
- Region regs = matchData .region ;
192
- for (int i = 0 ; i < regs .beg . length ; i ++) {
193
- assert regs .beg [ i ] != RubyMatchData .LAZY &&
194
- regs . end [ i ] != RubyMatchData .LAZY : "Group bounds must be computed before fixupMatchDataForStart()" ;
195
- if (regs .beg [ i ] >= 0 ) {
196
- regs .beg [ i ] += startPos ;
197
- regs .end [ i ] += startPos ;
193
+ MultiRegion regs = matchData .region ;
194
+ for (int i = 0 ; i < regs .getNumRegs () ; i ++) {
195
+ assert regs .getBeg ( i ) != RubyMatchData .LAZY && regs
196
+ . getEnd ( i ) != RubyMatchData .LAZY : "Group bounds must be computed before fixupMatchDataForStart()" ;
197
+ if (regs .getBeg ( i ) >= 0 ) {
198
+ regs .setBeg ( i , regs . getBeg ( i ) + startPos ) ;
199
+ regs .setEnd ( i , regs . getEnd ( i ) + startPos ) ;
198
200
}
199
201
}
200
202
}
@@ -222,7 +224,7 @@ public abstract static class MatchDataCreateSingleGroupNode extends PrimitiveArr
222
224
223
225
@ Specialization
224
226
Object create (Object regexp , Object string , int start , int end ) {
225
- final Region region = new Region (start , end );
227
+ final MultiRegion region = new MultiRegion (start , end );
226
228
RubyMatchData matchData = new RubyMatchData (
227
229
coreLibrary ().matchDataClass ,
228
230
getLanguage ().matchDataShape ,
@@ -254,12 +256,12 @@ Object getIndex(RubyMatchData matchData, int index, NotProvided length,
254
256
@ Cached @ Exclusive InlinedConditionProfile hasValueProfile ,
255
257
@ Cached TruffleString .SubstringByteIndexNode substringNode ) {
256
258
257
- final Region region = matchData .region ;
259
+ final MultiRegion region = matchData .region ;
258
260
if (normalizedIndexProfile .profile (this , index < 0 )) {
259
- index += region .numRegs ;
261
+ index += region .getNumRegs () ;
260
262
}
261
263
262
- if (indexOutOfBoundsProfile .profile (this , index < 0 || index >= region .numRegs )) {
264
+ if (indexOutOfBoundsProfile .profile (this , index < 0 || index >= region .getNumRegs () )) {
263
265
return nil ;
264
266
} else {
265
267
final int start = getStart (this , matchData , index , lazyProfile , libInterop );
@@ -510,7 +512,7 @@ Object begin(RubyMatchData matchData, int index,
510
512
511
513
if (multiByteCharacterProfile .profile (this ,
512
514
!singleByteOptimizableNode .execute (this , matchDataSource , encoding ))) {
513
- return getCharOffsets (matchData , matchDataSource , encoding ).beg [ index ] ;
515
+ return getCharOffsets (matchData , matchDataSource , encoding ).getBeg ( index ) ;
514
516
}
515
517
516
518
return begin ;
@@ -525,7 +527,7 @@ Object beginError(RubyMatchData matchData, int index) {
525
527
}
526
528
527
529
protected boolean inBounds (RubyMatchData matchData , int index ) {
528
- return index >= 0 && index < matchData .region .numRegs ;
530
+ return index >= 0 && index < matchData .region .getNumRegs () ;
529
531
}
530
532
}
531
533
@@ -548,12 +550,12 @@ Object[] getValues(RubyMatchData matchData,
548
550
@ Cached InlinedLoopConditionProfile loopProfile ,
549
551
@ Cached TruffleString .SubstringByteIndexNode substringNode ) {
550
552
final Object source = matchData .source ;
551
- final Region region = matchData .region ;
552
- final Object [] values = new Object [region .numRegs ];
553
+ final MultiRegion region = matchData .region ;
554
+ final Object [] values = new Object [region .getNumRegs () ];
553
555
554
556
int n = 0 ;
555
557
try {
556
- for (; loopProfile .inject (this , n < region .numRegs ); n ++) {
558
+ for (; loopProfile .inject (this , n < region .getNumRegs () ); n ++) {
557
559
final int start = getStart (this , matchData , n , lazyProfile , interop );
558
560
final int end = getEnd (this , matchData , n , lazyProfile , interop );
559
561
@@ -596,7 +598,7 @@ Object end(RubyMatchData matchData, int index,
596
598
597
599
if (multiByteCharacterProfile .profile (this ,
598
600
!singleByteOptimizableNode .execute (this , matchDataSource , encoding ))) {
599
- return getCharOffsets (matchData , matchDataSource , encoding ).end [ index ] ;
601
+ return getCharOffsets (matchData , matchDataSource , encoding ).getEnd ( index ) ;
600
602
}
601
603
602
604
return end ;
@@ -611,7 +613,7 @@ Object endError(RubyMatchData matchData, int index) {
611
613
}
612
614
613
615
protected boolean inBounds (RubyMatchData matchData , int index ) {
614
- return index >= 0 && index < matchData .region .numRegs ;
616
+ return index >= 0 && index < matchData .region .getNumRegs () ;
615
617
}
616
618
}
617
619
@@ -640,7 +642,7 @@ Object byteBeginError(RubyMatchData matchData, int index) {
640
642
}
641
643
642
644
protected boolean inBounds (RubyMatchData matchData , int index ) {
643
- return index >= 0 && index < matchData .region .numRegs ;
645
+ return index >= 0 && index < matchData .region .getNumRegs () ;
644
646
}
645
647
}
646
648
@@ -669,7 +671,7 @@ Object byteEndError(RubyMatchData matchData, int index) {
669
671
}
670
672
671
673
protected boolean inBounds (RubyMatchData matchData , int index ) {
672
- return index >= 0 && index < matchData .region .numRegs ;
674
+ return index >= 0 && index < matchData .region .getNumRegs () ;
673
675
}
674
676
}
675
677
@@ -678,7 +680,7 @@ public abstract static class LengthNode extends CoreMethodArrayArgumentsNode {
678
680
679
681
@ Specialization
680
682
int length (RubyMatchData matchData ) {
681
- return matchData .region .numRegs ;
683
+ return matchData .region .getNumRegs () ;
682
684
}
683
685
684
686
}
0 commit comments