Skip to content

Commit b984090

Browse files
committed
special handling for int valued slice
1 parent f4287bb commit b984090

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,9 +1941,29 @@ protected boolean isListSubtype(VirtualFrame frame, Object obj, GetClassNode get
19411941
}
19421942

19431943
@Builtin(name = "PyList_GetSlice", minNumOfPositionalArgs = 3)
1944+
@TypeSystemReference(PythonTypes.class)
19441945
@GenerateNodeFactory
19451946
abstract static class PyListGetSliceNode extends PythonTernaryBuiltinNode {
19461947

1948+
@Specialization
1949+
Object getSlice(VirtualFrame frame, PList list, long iLow, long iHigh,
1950+
@Cached com.oracle.graal.python.builtins.objects.list.ListBuiltins.GetItemNode getItemNode,
1951+
@Cached SliceLiteralNode sliceNode,
1952+
@Cached BranchProfile isIntRangeProfile,
1953+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
1954+
@Cached GetNativeNullNode getNativeNullNode) {
1955+
try {
1956+
if (PInt.isIntRange(iLow) && PInt.isIntRange(iHigh)) {
1957+
isIntRangeProfile.enter();
1958+
return getItemNode.execute(frame, list, sliceNode.execute(frame, (int) iLow, (int) iHigh, PNone.NONE));
1959+
}
1960+
return getItemNode.execute(frame, list, sliceNode.execute(frame, iLow, iHigh, PNone.NONE));
1961+
} catch (PException e) {
1962+
transformExceptionToNativeNode.execute(e);
1963+
return getNativeNullNode.execute();
1964+
}
1965+
}
1966+
19471967
@Specialization
19481968
Object getSlice(VirtualFrame frame, PList list, Object iLow, Object iHigh,
19491969
@Cached com.oracle.graal.python.builtins.objects.list.ListBuiltins.GetItemNode getItemNode,
@@ -1983,9 +2003,29 @@ protected boolean isListSubtype(VirtualFrame frame, Object obj, GetClassNode get
19832003
}
19842004

19852005
@Builtin(name = "PyList_SetSlice", minNumOfPositionalArgs = 4)
2006+
@TypeSystemReference(PythonTypes.class)
19862007
@GenerateNodeFactory
19872008
abstract static class PyListSetSliceNode extends PythonQuaternaryBuiltinNode {
19882009

2010+
@Specialization
2011+
Object getSlice(VirtualFrame frame, PList list, long iLow, long iHigh, Object s,
2012+
@Cached com.oracle.graal.python.builtins.objects.list.ListBuiltins.SetItemNode setItemNode,
2013+
@Cached SliceLiteralNode sliceNode,
2014+
@Cached BranchProfile isIntRangeProfile,
2015+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
2016+
try {
2017+
if (PInt.isIntRange(iLow) && PInt.isIntRange(iHigh)) {
2018+
isIntRangeProfile.enter();
2019+
setItemNode.execute(frame, list, sliceNode.execute(frame, (int) iLow, (int) iHigh, PNone.NONE), s);
2020+
}
2021+
setItemNode.execute(frame, list, sliceNode.execute(frame, iLow, iHigh, PNone.NONE), s);
2022+
return 0;
2023+
} catch (PException e) {
2024+
transformExceptionToNativeNode.execute(e);
2025+
return -1;
2026+
}
2027+
}
2028+
19892029
@Specialization
19902030
Object getSlice(VirtualFrame frame, PList list, Object iLow, Object iHigh, Object s,
19912031
@Cached com.oracle.graal.python.builtins.objects.list.ListBuiltins.SetItemNode setItemNode,

0 commit comments

Comments
 (0)