Skip to content

Commit 446b5ba

Browse files
committed
executeGetIndex() is only called with an int index
1 parent f5cad1f commit 446b5ba

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.Arrays;
1313
import java.util.Iterator;
1414

15-
import com.oracle.truffle.api.library.CachedLibrary;
1615
import org.jcodings.Encoding;
1716
import org.joni.NameEntry;
1817
import org.joni.Regex;
@@ -30,8 +29,8 @@
3029
import org.truffleruby.core.array.ArrayIndexNodes;
3130
import org.truffleruby.core.array.ArrayOperations;
3231
import org.truffleruby.core.array.ArrayUtils;
33-
import org.truffleruby.core.cast.ToIntNode;
3432
import org.truffleruby.core.cast.IntegerCastNode;
33+
import org.truffleruby.core.cast.ToIntNode;
3534
import org.truffleruby.core.regexp.MatchDataNodesFactory.ValuesNodeFactory;
3635
import org.truffleruby.core.rope.Rope;
3736
import org.truffleruby.core.rope.RopeNodes;
@@ -41,19 +40,19 @@
4140
import org.truffleruby.core.symbol.RubySymbol;
4241
import org.truffleruby.language.Nil;
4342
import org.truffleruby.language.NotProvided;
44-
import org.truffleruby.language.library.RubyLibrary;
4543
import org.truffleruby.language.RubyNode;
4644
import org.truffleruby.language.Visibility;
4745
import org.truffleruby.language.control.RaiseException;
4846
import org.truffleruby.language.dispatch.CallDispatchHeadNode;
47+
import org.truffleruby.language.library.RubyLibrary;
4948
import org.truffleruby.language.objects.AllocateObjectNode;
5049

5150
import com.oracle.truffle.api.CompilerDirectives;
5251
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5352
import com.oracle.truffle.api.dsl.Cached;
5453
import com.oracle.truffle.api.dsl.Specialization;
54+
import com.oracle.truffle.api.library.CachedLibrary;
5555
import com.oracle.truffle.api.object.DynamicObject;
56-
import com.oracle.truffle.api.profiles.BranchProfile;
5756
import com.oracle.truffle.api.profiles.ConditionProfile;
5857

5958
@CoreModule(value = "MatchData", isClass = true)
@@ -230,7 +229,7 @@ public static GetIndexNode create(RubyNode... nodes) {
230229
return MatchDataNodesFactory.GetIndexNodeFactory.create(nodes);
231230
}
232231

233-
public abstract Object executeGetIndex(Object matchData, Object index, Object length);
232+
protected abstract Object executeGetIndex(Object matchData, int index, NotProvided length);
234233

235234
@Specialization
236235
protected Object getIndex(DynamicObject matchData, int index, NotProvided length,
@@ -283,14 +282,12 @@ protected Object getIndexSymbolSingleMatch(DynamicObject matchData, RubySymbol i
283282
return executeGetIndex(matchData, backRefIndex, NotProvided.INSTANCE);
284283
} else {
285284
final int i = getBackRef(matchData, regexp, name);
286-
287285
return executeGetIndex(matchData, i, NotProvided.INSTANCE);
288286
}
289287
}
290288

291289
@Specialization
292-
protected Object getIndexSymbol(DynamicObject matchData, RubySymbol index, NotProvided length,
293-
@Cached BranchProfile errorProfile) {
290+
protected Object getIndexSymbol(DynamicObject matchData, RubySymbol index, NotProvided length) {
294291
return executeGetIndex(matchData, getBackRefFromSymbol(matchData, index), NotProvided.INSTANCE);
295292
}
296293

@@ -299,7 +296,8 @@ protected Object getIndexString(DynamicObject matchData, DynamicObject index, No
299296
return executeGetIndex(matchData, getBackRefFromString(matchData, index), NotProvided.INSTANCE);
300297
}
301298

302-
@Specialization(guards = { "!isRubySymbol(index)", "!isRubyString(index)", "!isIntRange(index)" })
299+
@Specialization(
300+
guards = { "!isInteger(index)", "!isRubySymbol(index)", "!isRubyString(index)", "!isIntRange(index)" })
303301
protected Object getIndex(DynamicObject matchData, Object index, NotProvided length,
304302
@Cached ToIntNode toIntNode) {
305303
return executeGetIndex(matchData, toIntNode.execute(index), NotProvided.INSTANCE);

0 commit comments

Comments
 (0)