|
49 | 49 | import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
|
50 | 50 | import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
|
51 | 51 | import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
|
| 52 | +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes; |
52 | 53 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
|
53 | 54 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode;
|
54 | 55 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode;
|
@@ -2935,13 +2936,47 @@ public abstract static class SetLenNode extends Node {
|
2935 | 2936 | public abstract void execute(Node inliningTarget, SequenceStorage s, int len);
|
2936 | 2937 |
|
2937 | 2938 | @Specialization(limit = "MAX_SEQUENCE_STORAGES", guards = "s.getClass() == cachedClass")
|
2938 |
| - static void doSpecial(SequenceStorage s, int len, |
| 2939 | + static void doSpecial(BasicSequenceStorage s, int len, |
2939 | 2940 | @Cached("s.getClass()") Class<? extends SequenceStorage> cachedClass) {
|
2940 | 2941 | cachedClass.cast(s).setNewLength(len);
|
2941 | 2942 | }
|
2942 | 2943 |
|
2943 | 2944 | @Specialization(replaces = "doSpecial")
|
2944 |
| - static void doGeneric(SequenceStorage s, int len) { |
| 2945 | + static void doGeneric(BasicSequenceStorage s, int len) { |
| 2946 | + s.setNewLength(len); |
| 2947 | + } |
| 2948 | + |
| 2949 | + @Specialization |
| 2950 | + static void doNative(NativeSequenceStorage s, int len, |
| 2951 | + @Cached(inline = false) SetNativeLenNode setLen) { |
| 2952 | + setLen.execute(s, len); |
| 2953 | + } |
| 2954 | + } |
| 2955 | + |
| 2956 | + @GenerateUncached |
| 2957 | + @GenerateInline(false) // Uncommon node |
| 2958 | + public abstract static class SetNativeLenNode extends Node { |
| 2959 | + |
| 2960 | + public abstract void execute(NativeSequenceStorage s, int len); |
| 2961 | + |
| 2962 | + @Specialization(guards = "len < s.length()") |
| 2963 | + @InliningCutoff |
| 2964 | + static void doShrink(NativeSequenceStorage s, int len, |
| 2965 | + @Bind("this") Node inliningTarget, |
| 2966 | + @Cached CStructAccess.ReadPointerNode readNode, |
| 2967 | + @Cached CExtNodes.DecRefPointerNode decRefPointerNode) { |
| 2968 | + if (len < s.length()) { |
| 2969 | + // When shrinking, we need to decref the items that are now past the end |
| 2970 | + for (int i = len; i < s.length(); i++) { |
| 2971 | + Object elementPointer = readNode.readArrayElement(s.getPtr(), i); |
| 2972 | + decRefPointerNode.execute(inliningTarget, elementPointer); |
| 2973 | + } |
| 2974 | + } |
| 2975 | + s.setNewLength(len); |
| 2976 | + } |
| 2977 | + |
| 2978 | + @Fallback |
| 2979 | + static void doEnlarge(NativeSequenceStorage s, int len) { |
2945 | 2980 | s.setNewLength(len);
|
2946 | 2981 | }
|
2947 | 2982 | }
|
@@ -3025,29 +3060,27 @@ public abstract static class DeleteItemNode extends SequenceStorageBaseNode {
|
3025 | 3060 |
|
3026 | 3061 | public abstract void execute(Node node, SequenceStorage s, int idx);
|
3027 | 3062 |
|
3028 |
| - @Specialization(limit = "MAX_SEQUENCE_STORAGES", guards = {"s.getClass() == cachedClass", "isLastItem(s, cachedClass, idx)"}) |
3029 |
| - static void doLastItem(SequenceStorage s, @SuppressWarnings("unused") int idx, |
3030 |
| - @Cached("s.getClass()") Class<? extends SequenceStorage> cachedClass) { |
3031 |
| - SequenceStorage profiled = cachedClass.cast(s); |
3032 |
| - profiled.setNewLength(profiled.length() - 1); |
| 3063 | + @Specialization(guards = "isLastItem(s, idx)") |
| 3064 | + static void doLastItem(Node inliningTarget, SequenceStorage s, @SuppressWarnings("unused") int idx, |
| 3065 | + @Shared @Cached SetLenNode setLenNode) { |
| 3066 | + setLenNode.execute(inliningTarget, s, s.length() - 1); |
3033 | 3067 | }
|
3034 | 3068 |
|
3035 |
| - @Specialization(limit = "MAX_SEQUENCE_STORAGES", guards = "s.getClass() == cachedClass") |
3036 |
| - static void doGeneric(Node inliningTarget, SequenceStorage s, @SuppressWarnings("unused") int idx, |
3037 |
| - @Cached(inline = false) GetItemScalarNode getItemNode, |
| 3069 | + @Specialization |
| 3070 | + static void doGeneric(Node inliningTarget, SequenceStorage s, int idx, |
| 3071 | + @Cached GetItemScalarNode getItemNode, |
3038 | 3072 | @Cached SetItemScalarNode setItemNode,
|
3039 |
| - @Cached("s.getClass()") Class<? extends SequenceStorage> cachedClass) { |
3040 |
| - SequenceStorage profiled = cachedClass.cast(s); |
3041 |
| - int len = profiled.length(); |
| 3073 | + @Shared @Cached SetLenNode setLenNode) { |
| 3074 | + int len = s.length(); |
3042 | 3075 |
|
3043 | 3076 | for (int i = idx; i < len - 1; i++) {
|
3044 |
| - setItemNode.execute(inliningTarget, profiled, i, getItemNode.execute(inliningTarget, profiled, i + 1)); |
| 3077 | + setItemNode.execute(inliningTarget, s, i, getItemNode.execute(inliningTarget, s, i + 1)); |
3045 | 3078 | }
|
3046 |
| - profiled.setNewLength(len - 1); |
| 3079 | + setLenNode.execute(inliningTarget, s, len - 1); |
3047 | 3080 | }
|
3048 | 3081 |
|
3049 |
| - protected static boolean isLastItem(SequenceStorage s, Class<? extends SequenceStorage> cachedClass, int idx) { |
3050 |
| - return idx == cachedClass.cast(s).length() - 1; |
| 3082 | + protected static boolean isLastItem(SequenceStorage s, int idx) { |
| 3083 | + return idx == s.length() - 1; |
3051 | 3084 | }
|
3052 | 3085 | }
|
3053 | 3086 |
|
|
0 commit comments