Skip to content

Commit 5f92d33

Browse files
committed
Do not initialize supported binary input types at image build time
1 parent 048f617 commit 5f92d33

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,6 @@ protected TRegexCache getTRegexCache(Object pattern) {
543543

544544
abstract static class RECheckInputTypeNode extends PNodeWithRaise {
545545

546-
private static final PTuple SUPPORTED_BINARY_INPUT_TYPES = PythonObjectFactory.getUncached().createTuple(new Object[]{PythonBuiltinClassType.PBytes, PythonBuiltinClassType.PByteArray,
547-
PythonBuiltinClassType.PMMap, PythonBuiltinClassType.PMemoryView, PythonBuiltinClassType.PArray});
548546
private static final TruffleString T_UNSUPPORTED_INPUT_TYPE = tsLiteral("expected string or bytes-like object");
549547
private static final TruffleString T_UNEXPECTED_BYTES = tsLiteral("cannot use a string pattern on a bytes-like object");
550548
private static final TruffleString T_UNEXPECTED_STR = tsLiteral("cannot use a bytes pattern on a string-like object");
@@ -554,12 +552,13 @@ abstract static class RECheckInputTypeNode extends PNodeWithRaise {
554552
@Specialization
555553
protected void check(VirtualFrame frame, Object input, boolean expectBytes,
556554
@Bind("this") Node inliningTarget,
555+
@Cached("getSupportedBinaryInputTypes()") PTuple supportedBinaryInputTypes,
557556
@Cached BuiltinFunctions.IsInstanceNode isStringNode,
558557
@Cached BuiltinFunctions.IsInstanceNode isBytesNode,
559558
@Cached InlinedConditionProfile unsupportedInputTypeProfile,
560559
@Cached InlinedConditionProfile unexpectedInputTypeProfile) {
561560
boolean isString = (boolean) isStringNode.execute(frame, input, PythonBuiltinClassType.PString);
562-
boolean isBytes = !isString && (boolean) isBytesNode.execute(frame, input, SUPPORTED_BINARY_INPUT_TYPES);
561+
boolean isBytes = !isString && (boolean) isBytesNode.execute(frame, input, supportedBinaryInputTypes);
563562
if (unsupportedInputTypeProfile.profile(inliningTarget, !isString && !isBytes)) {
564563
throw getRaiseNode().raise(TypeError, T_UNSUPPORTED_INPUT_TYPE);
565564
}
@@ -571,6 +570,12 @@ protected void check(VirtualFrame frame, Object input, boolean expectBytes,
571570
}
572571
}
573572
}
573+
574+
@NeverDefault
575+
protected PTuple getSupportedBinaryInputTypes() {
576+
return PythonObjectFactory.getUncached().createTuple(new Object[]{PythonBuiltinClassType.PBytes, PythonBuiltinClassType.PByteArray, PythonBuiltinClassType.PMMap,
577+
PythonBuiltinClassType.PMemoryView, PythonBuiltinClassType.PArray});
578+
}
574579
}
575580

576581
abstract static class CreateMatchFromTRegexResultNode extends PNodeWithContext {

0 commit comments

Comments
 (0)