Skip to content

Commit 44311a0

Browse files
committed
Adopt breaking change in joni and splitting a Region class into a SingleRegion and MultiRegion
1 parent e9da0ed commit 44311a0

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

src/main/java/org/truffleruby/core/regexp/MatchDataNodes.java

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,26 @@ private static int getGroupBound(InteropLibrary interop, RubyMatchData matchData
7878

7979
private static int getStart(Node node, RubyMatchData matchData, int index, InlinedConditionProfile lazyProfile,
8080
InteropLibrary interop) {
81-
int start = matchData.region.beg[index];
81+
int start = matchData.region.getBeg(index);
8282
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));
8484
} else {
8585
return start;
8686
}
8787
}
8888

8989
private static int getEnd(Node node, RubyMatchData matchData, int index, InlinedConditionProfile lazyProfile,
9090
InteropLibrary interop) {
91-
int end = matchData.region.end[index];
91+
int end = matchData.region.getEnd(index);
9292
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));
9494
} else {
9595
return end;
9696
}
9797
}
9898

9999
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++) {
101101
getStart(null, matchData, i, InlinedConditionProfile.getUncached(), interop);
102102
getEnd(null, matchData, i, InlinedConditionProfile.getUncached(), interop);
103103
}
@@ -111,13 +111,13 @@ private static Region getCharOffsetsManyRegs(RubyMatchData matchData, AbstractTr
111111
assert !encoding.isSingleByte : "Should be checked by callers";
112112

113113
final Region regs = matchData.region;
114-
int numRegs = regs.numRegs;
114+
int numRegs = regs.getNumRegs();
115115

116116
if (matchData.tRegexResult != null) {
117117
forceLazyMatchData(matchData, InteropLibrary.getUncached(matchData.tRegexResult));
118118
}
119119

120-
final Region charOffsets = new Region(numRegs);
120+
final Region charOffsets = Region.newRegion(numRegs);
121121

122122
final Pair[] pairs = new Pair[numRegs * 2];
123123
for (int i = 0; i < pairs.length; i++) {
@@ -126,23 +126,24 @@ private static Region getCharOffsetsManyRegs(RubyMatchData matchData, AbstractTr
126126

127127
int numPos = 0;
128128
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);
132132
}
133133
}
134134

135135
updatePairs(source, encoding, pairs);
136136

137137
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);
141142
} 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);
146147
}
147148
}
148149

@@ -189,12 +190,12 @@ private static Region getCharOffsets(RubyMatchData matchData, AbstractTruffleStr
189190
private static void fixupMatchDataForStart(RubyMatchData matchData, int startPos) {
190191
assert startPos != 0;
191192
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);
198199
}
199200
}
200201
}
@@ -222,7 +223,7 @@ public abstract static class MatchDataCreateSingleGroupNode extends PrimitiveArr
222223

223224
@Specialization
224225
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);
226227
RubyMatchData matchData = new RubyMatchData(
227228
coreLibrary().matchDataClass,
228229
getLanguage().matchDataShape,
@@ -256,10 +257,10 @@ Object getIndex(RubyMatchData matchData, int index, NotProvided length,
256257

257258
final Region region = matchData.region;
258259
if (normalizedIndexProfile.profile(this, index < 0)) {
259-
index += region.numRegs;
260+
index += region.getNumRegs();
260261
}
261262

262-
if (indexOutOfBoundsProfile.profile(this, index < 0 || index >= region.numRegs)) {
263+
if (indexOutOfBoundsProfile.profile(this, index < 0 || index >= region.getNumRegs())) {
263264
return nil;
264265
} else {
265266
final int start = getStart(this, matchData, index, lazyProfile, libInterop);
@@ -505,7 +506,7 @@ Object begin(RubyMatchData matchData, int index,
505506

506507
if (multiByteCharacterProfile.profile(this,
507508
!singleByteOptimizableNode.execute(this, matchDataSource, encoding))) {
508-
return getCharOffsets(matchData, matchDataSource, encoding).beg[index];
509+
return getCharOffsets(matchData, matchDataSource, encoding).getBeg(index);
509510
}
510511

511512
return begin;
@@ -520,7 +521,7 @@ Object beginError(RubyMatchData matchData, int index) {
520521
}
521522

522523
protected boolean inBounds(RubyMatchData matchData, int index) {
523-
return index >= 0 && index < matchData.region.numRegs;
524+
return index >= 0 && index < matchData.region.getNumRegs();
524525
}
525526
}
526527

@@ -544,11 +545,11 @@ Object[] getValues(RubyMatchData matchData,
544545
@Cached TruffleString.SubstringByteIndexNode substringNode) {
545546
final Object source = matchData.source;
546547
final Region region = matchData.region;
547-
final Object[] values = new Object[region.numRegs];
548+
final Object[] values = new Object[region.getNumRegs()];
548549

549550
int n = 0;
550551
try {
551-
for (; loopProfile.inject(this, n < region.numRegs); n++) {
552+
for (; loopProfile.inject(this, n < region.getNumRegs()); n++) {
552553
final int start = getStart(this, matchData, n, lazyProfile, interop);
553554
final int end = getEnd(this, matchData, n, lazyProfile, interop);
554555

@@ -591,7 +592,7 @@ Object end(RubyMatchData matchData, int index,
591592

592593
if (multiByteCharacterProfile.profile(this,
593594
!singleByteOptimizableNode.execute(this, matchDataSource, encoding))) {
594-
return getCharOffsets(matchData, matchDataSource, encoding).end[index];
595+
return getCharOffsets(matchData, matchDataSource, encoding).getEnd(index);
595596
}
596597

597598
return end;
@@ -606,7 +607,7 @@ Object endError(RubyMatchData matchData, int index) {
606607
}
607608

608609
protected boolean inBounds(RubyMatchData matchData, int index) {
609-
return index >= 0 && index < matchData.region.numRegs;
610+
return index >= 0 && index < matchData.region.getNumRegs();
610611
}
611612
}
612613

@@ -635,7 +636,7 @@ Object byteBeginError(RubyMatchData matchData, int index) {
635636
}
636637

637638
protected boolean inBounds(RubyMatchData matchData, int index) {
638-
return index >= 0 && index < matchData.region.numRegs;
639+
return index >= 0 && index < matchData.region.getNumRegs();
639640
}
640641
}
641642

@@ -664,7 +665,7 @@ Object byteEndError(RubyMatchData matchData, int index) {
664665
}
665666

666667
protected boolean inBounds(RubyMatchData matchData, int index) {
667-
return index >= 0 && index < matchData.region.numRegs;
668+
return index >= 0 && index < matchData.region.getNumRegs();
668669
}
669670
}
670671

@@ -673,7 +674,7 @@ public abstract static class LengthNode extends CoreMethodArrayArgumentsNode {
673674

674675
@Specialization
675676
int length(RubyMatchData matchData) {
676-
return matchData.region.numRegs;
677+
return matchData.region.getNumRegs();
677678
}
678679

679680
}

src/main/java/org/truffleruby/core/regexp/TruffleRegexpNodes.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -984,12 +984,12 @@ static Object matchInRegionTRegex(
984984
final int groupCount = groupCountProfile
985985
.profile(node, (int) InteropNodes.readMember(node, regexInterop, tRegex, "groupCount",
986986
translateInteropExceptionNode));
987-
final Region region = new Region(groupCount);
987+
final Region region = Region.newRegion(groupCount);
988988

989989
try {
990990
for (int group = 0; loopProfile.inject(node, group < groupCount); group++) {
991-
region.beg[group] = RubyMatchData.LAZY;
992-
region.end[group] = RubyMatchData.LAZY;
991+
region.setBeg(group, RubyMatchData.LAZY);
992+
region.setEnd(group, RubyMatchData.LAZY);
993993
TruffleSafepoint.poll(node);
994994
}
995995
} finally {
@@ -1144,9 +1144,9 @@ private int runMatch(Matcher matcher, int startPos, int range, boolean onlyMatch
11441144
}
11451145

11461146
private boolean assertValidRegion(Region region) {
1147-
for (int i = 0; i < region.numRegs; i++) {
1148-
assert region.beg[i] >= 0 || region.beg[i] == RubyMatchData.MISSING;
1149-
assert region.end[i] >= 0 || region.end[i] == RubyMatchData.MISSING;
1147+
for (int i = 0; i < region.getNumRegs(); i++) {
1148+
assert region.getBeg(i) >= 0 || region.getBeg(i) == RubyMatchData.MISSING;
1149+
assert region.getEnd(i) >= 0 || region.getEnd(i) == RubyMatchData.MISSING;
11501150
}
11511151
return true;
11521152
}

0 commit comments

Comments
 (0)