@@ -78,26 +78,26 @@ 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
}
@@ -111,13 +111,13 @@ private static Region getCharOffsetsManyRegs(RubyMatchData matchData, AbstractTr
111
111
assert !encoding .isSingleByte : "Should be checked by callers" ;
112
112
113
113
final Region regs = matchData .region ;
114
- int numRegs = regs .numRegs ;
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 Region charOffsets = Region . newRegion (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
@@ -189,12 +190,12 @@ private static Region getCharOffsets(RubyMatchData matchData, AbstractTruffleStr
189
190
private static void fixupMatchDataForStart (RubyMatchData matchData , int startPos ) {
190
191
assert startPos != 0 ;
191
192
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
+ for (int i = 0 ; i < regs .getNumRegs () ; i ++) {
194
+ assert regs .getBeg ( i ) != RubyMatchData .LAZY && regs
195
+ . getEnd ( i ) != RubyMatchData .LAZY : "Group bounds must be computed before fixupMatchDataForStart()" ;
196
+ if (regs .getBeg ( i ) >= 0 ) {
197
+ regs .setBeg ( i , regs . getBeg ( i ) + startPos ) ;
198
+ regs .setEnd ( i , regs . getEnd ( i ) + startPos ) ;
198
199
}
199
200
}
200
201
}
@@ -222,7 +223,7 @@ public abstract static class MatchDataCreateSingleGroupNode extends PrimitiveArr
222
223
223
224
@ Specialization
224
225
Object create (Object regexp , Object string , int start , int end ) {
225
- final Region region = new Region (start , end );
226
+ final Region region = Region . newRegion (start , end );
226
227
RubyMatchData matchData = new RubyMatchData (
227
228
coreLibrary ().matchDataClass ,
228
229
getLanguage ().matchDataShape ,
@@ -256,10 +257,10 @@ Object getIndex(RubyMatchData matchData, int index, NotProvided length,
256
257
257
258
final Region region = matchData .region ;
258
259
if (normalizedIndexProfile .profile (this , index < 0 )) {
259
- index += region .numRegs ;
260
+ index += region .getNumRegs () ;
260
261
}
261
262
262
- if (indexOutOfBoundsProfile .profile (this , index < 0 || index >= region .numRegs )) {
263
+ if (indexOutOfBoundsProfile .profile (this , index < 0 || index >= region .getNumRegs () )) {
263
264
return nil ;
264
265
} else {
265
266
final int start = getStart (this , matchData , index , lazyProfile , libInterop );
@@ -505,7 +506,7 @@ Object begin(RubyMatchData matchData, int index,
505
506
506
507
if (multiByteCharacterProfile .profile (this ,
507
508
!singleByteOptimizableNode .execute (this , matchDataSource , encoding ))) {
508
- return getCharOffsets (matchData , matchDataSource , encoding ).beg [ index ] ;
509
+ return getCharOffsets (matchData , matchDataSource , encoding ).getBeg ( index ) ;
509
510
}
510
511
511
512
return begin ;
@@ -520,7 +521,7 @@ Object beginError(RubyMatchData matchData, int index) {
520
521
}
521
522
522
523
protected boolean inBounds (RubyMatchData matchData , int index ) {
523
- return index >= 0 && index < matchData .region .numRegs ;
524
+ return index >= 0 && index < matchData .region .getNumRegs () ;
524
525
}
525
526
}
526
527
@@ -544,11 +545,11 @@ Object[] getValues(RubyMatchData matchData,
544
545
@ Cached TruffleString .SubstringByteIndexNode substringNode ) {
545
546
final Object source = matchData .source ;
546
547
final Region region = matchData .region ;
547
- final Object [] values = new Object [region .numRegs ];
548
+ final Object [] values = new Object [region .getNumRegs () ];
548
549
549
550
int n = 0 ;
550
551
try {
551
- for (; loopProfile .inject (this , n < region .numRegs ); n ++) {
552
+ for (; loopProfile .inject (this , n < region .getNumRegs () ); n ++) {
552
553
final int start = getStart (this , matchData , n , lazyProfile , interop );
553
554
final int end = getEnd (this , matchData , n , lazyProfile , interop );
554
555
@@ -591,7 +592,7 @@ Object end(RubyMatchData matchData, int index,
591
592
592
593
if (multiByteCharacterProfile .profile (this ,
593
594
!singleByteOptimizableNode .execute (this , matchDataSource , encoding ))) {
594
- return getCharOffsets (matchData , matchDataSource , encoding ).end [ index ] ;
595
+ return getCharOffsets (matchData , matchDataSource , encoding ).getEnd ( index ) ;
595
596
}
596
597
597
598
return end ;
@@ -606,7 +607,7 @@ Object endError(RubyMatchData matchData, int index) {
606
607
}
607
608
608
609
protected boolean inBounds (RubyMatchData matchData , int index ) {
609
- return index >= 0 && index < matchData .region .numRegs ;
610
+ return index >= 0 && index < matchData .region .getNumRegs () ;
610
611
}
611
612
}
612
613
@@ -635,7 +636,7 @@ Object byteBeginError(RubyMatchData matchData, int index) {
635
636
}
636
637
637
638
protected boolean inBounds (RubyMatchData matchData , int index ) {
638
- return index >= 0 && index < matchData .region .numRegs ;
639
+ return index >= 0 && index < matchData .region .getNumRegs () ;
639
640
}
640
641
}
641
642
@@ -664,7 +665,7 @@ Object byteEndError(RubyMatchData matchData, int index) {
664
665
}
665
666
666
667
protected boolean inBounds (RubyMatchData matchData , int index ) {
667
- return index >= 0 && index < matchData .region .numRegs ;
668
+ return index >= 0 && index < matchData .region .getNumRegs () ;
668
669
}
669
670
}
670
671
@@ -673,7 +674,7 @@ public abstract static class LengthNode extends CoreMethodArrayArgumentsNode {
673
674
674
675
@ Specialization
675
676
int length (RubyMatchData matchData ) {
676
- return matchData .region .numRegs ;
677
+ return matchData .region .getNumRegs () ;
677
678
}
678
679
679
680
}
0 commit comments