@@ -54,32 +54,46 @@ protected DynamicObject slice(DynamicObject array, int start, int length) {
54
54
@ Specialization (guards = "isIntRange(range)" )
55
55
protected DynamicObject slice (DynamicObject array , DynamicObject range , NotProvided len ,
56
56
@ Cached ("createBinaryProfile()" ) ConditionProfile negativeBeginProfile ,
57
- @ Cached ("createBinaryProfile()" ) ConditionProfile negativeEndProfile ) {
57
+ @ Cached ("createBinaryProfile()" ) ConditionProfile negativeEndProfile ,
58
+ @ Cached ("create()" ) ArrayReadSliceNormalizedNode readNormalizedSliceNode ) {
58
59
final int size = getSize (array );
59
- final int normalizedIndex = ArrayOperations
60
+ final int normalizedBegin = ArrayOperations
60
61
.normalizeIndex (size , Layouts .INT_RANGE .getBegin (range ), negativeBeginProfile );
61
62
62
- if (normalizedIndex < 0 || normalizedIndex > size ) {
63
+ if (normalizedBegin < 0 || normalizedBegin > size ) {
63
64
return nil ();
64
65
} else {
65
66
final int end = ArrayOperations
66
67
.normalizeIndex (size , Layouts .INT_RANGE .getEnd (range ), negativeEndProfile );
67
68
final int exclusiveEnd = ArrayOperations
68
69
.clampExclusiveIndex (size , Layouts .INT_RANGE .getExcludedEnd (range ) ? end : end + 1 );
69
70
70
- if (exclusiveEnd <= normalizedIndex ) {
71
+ if (exclusiveEnd <= normalizedBegin ) {
71
72
return allocateObjectNode
72
73
.allocate (Layouts .BASIC_OBJECT .getLogicalClass (array ), ArrayStrategy .NULL_ARRAY_STORE , 0 );
73
74
}
74
75
75
- final int length = exclusiveEnd - normalizedIndex ;
76
+ return readNormalizedSliceNode .executeReadSlice (array , normalizedBegin , exclusiveEnd - normalizedBegin );
77
+ }
78
+ }
79
+
80
+ @ Specialization (guards = "isIntEndlessRange(getContext(), range)" )
81
+ protected DynamicObject endlessSlice (DynamicObject array , DynamicObject range , NotProvided len ,
82
+ @ Cached ("createBinaryProfile()" ) ConditionProfile negativeBeginProfile ,
83
+ @ Cached ("create()" ) ArrayReadSliceNormalizedNode readNormalizedSliceNode ) {
84
+ final int size = getSize (array );
85
+ final int normalizedBegin = ArrayOperations
86
+ .normalizeIndex (size , (int ) Layouts .OBJECT_RANGE .getBegin (range ), negativeBeginProfile );
76
87
77
- if (readNormalizedSliceNode == null ) {
78
- CompilerDirectives .transferToInterpreterAndInvalidate ();
79
- readNormalizedSliceNode = insert (ArrayReadSliceNormalizedNodeGen .create ());
88
+ if (normalizedBegin < 0 || normalizedBegin > size ) {
89
+ return nil ();
90
+ } else {
91
+ if (size == normalizedBegin ) {
92
+ return allocateObjectNode
93
+ .allocate (Layouts .BASIC_OBJECT .getLogicalClass (array ), ArrayStrategy .NULL_ARRAY_STORE , 0 );
80
94
}
81
95
82
- return readNormalizedSliceNode .executeReadSlice (array , normalizedIndex , length );
96
+ return readNormalizedSliceNode .executeReadSlice (array , normalizedBegin , size - normalizedBegin );
83
97
}
84
98
}
85
99
0 commit comments