47
47
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .StopIteration ;
48
48
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
49
49
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .ValueError ;
50
+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DICT__ ;
50
51
import static com .oracle .graal .python .nodes .SpecialMethodNames .__ADD__ ;
51
52
import static com .oracle .graal .python .nodes .SpecialMethodNames .__CONTAINS__ ;
52
53
import static com .oracle .graal .python .nodes .SpecialMethodNames .__DELITEM__ ;
74
75
import com .oracle .graal .python .annotations .ArgumentClinic .ClinicConversion ;
75
76
import com .oracle .graal .python .builtins .Builtin ;
76
77
import com .oracle .graal .python .builtins .CoreFunctions ;
78
+ import com .oracle .graal .python .builtins .Python3Core ;
77
79
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
78
80
import com .oracle .graal .python .builtins .PythonBuiltins ;
79
81
import com .oracle .graal .python .builtins .objects .PNone ;
93
95
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
94
96
import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
95
97
import com .oracle .graal .python .lib .PyObjectIsTrueNode ;
98
+ import com .oracle .graal .python .lib .PyObjectLookupAttr ;
99
+ import com .oracle .graal .python .lib .PyObjectSizeNode ;
96
100
import com .oracle .graal .python .nodes .ErrorMessages ;
97
101
import com .oracle .graal .python .nodes .PGuards ;
98
102
import com .oracle .graal .python .nodes .PRaiseNode ;
117
121
import com .oracle .graal .python .nodes .util .CastToJavaIntExactNode ;
118
122
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
119
123
import com .oracle .graal .python .runtime .PythonContext ;
120
- import com .oracle .graal .python .builtins .Python3Core ;
121
124
import com .oracle .graal .python .runtime .exception .PException ;
122
125
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
123
126
import com .oracle .truffle .api .CompilerDirectives ;
@@ -269,8 +272,9 @@ static PNone doGeneric(PDeque self) {
269
272
public abstract static class DequeCopyNode extends PythonUnaryBuiltinNode {
270
273
271
274
@ Specialization
272
- PDeque doGeneric (PDeque self ) {
273
- PDeque copy = factory ().createDeque ();
275
+ PDeque doGeneric (PDeque self ,
276
+ @ Cached GetClassNode getClassNode ) {
277
+ PDeque copy = factory ().createDeque (getClassNode .execute (self ));
274
278
copy .setMaxLength (self .getMaxLength ());
275
279
copy .addAll (self );
276
280
return copy ;
@@ -853,31 +857,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
853
857
static PNone doGeneric (PDeque self , int idx , Object value ,
854
858
@ Cached NormalizeIndexCustomMessageNode normalizeIndexNode ) {
855
859
int normIdx = normalizeIndexNode .execute (idx , self .getSize (), ErrorMessages .DEQUE_INDEX_OUT_OF_RANGE );
856
- doSetItem ( self , normIdx , value );
860
+ self . setItem ( normIdx , value != PNone . NO_VALUE ? value : null );
857
861
return PNone .NONE ;
858
862
}
859
-
860
- @ TruffleBoundary
861
- static void doSetItem (PDeque self , int idx , Object value ) {
862
- assert 0 <= idx && idx < self .getSize ();
863
- int n = self .getSize () - idx - 1 ;
864
- Object [] savedItems = new Object [n ];
865
- for (int i = 0 ; i < savedItems .length ; i ++) {
866
- savedItems [i ] = self .pop ();
867
- }
868
- // this removes the item we want to replace
869
- self .pop ();
870
- assert self .getSize () == idx ;
871
- if (value != PNone .NO_VALUE ) {
872
- self .append (value );
873
- }
874
-
875
- // re-add saved items
876
- for (int i = savedItems .length - 1 ; i >= 0 ; i --) {
877
- self .append (savedItems [i ]);
878
- }
879
- assert value != PNone .NO_VALUE && self .getSize () == n + idx + 1 || value == PNone .NO_VALUE && self .getSize () == n + idx ;
880
- }
881
863
}
882
864
883
865
@ Builtin (name = __DELITEM__ , minNumOfPositionalArgs = 2 , parameterNames = {"$self" , "n" })
@@ -894,7 +876,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
894
876
static PNone doGeneric (PDeque self , int idx ,
895
877
@ Cached NormalizeIndexCustomMessageNode normalizeIndexNode ) {
896
878
int normIdx = normalizeIndexNode .execute (idx , self .getSize (), ErrorMessages .DEQUE_INDEX_OUT_OF_RANGE );
897
- DequeSetItemNode . doSetItem ( self , normIdx , PNone . NO_VALUE );
879
+ self . setItem ( normIdx , null );
898
880
return PNone .NONE ;
899
881
}
900
882
}
@@ -966,12 +948,17 @@ static Object repr(PDeque self) {
966
948
abstract static class DequeReduceNode extends PythonUnaryBuiltinNode {
967
949
968
950
@ Specialization (limit = "1" )
969
- Object doGeneric (PDeque self ,
951
+ Object doGeneric (VirtualFrame frame , PDeque self ,
970
952
@ CachedLibrary ("self" ) PythonObjectLibrary lib ,
953
+ @ Cached PyObjectLookupAttr lookupAttr ,
954
+ @ Cached PyObjectSizeNode sizeNode ,
971
955
@ Cached GetClassNode getClassNode ,
972
956
@ Cached ConditionProfile profile ) {
973
957
Object clazz = getPythonClass (getClassNode .execute (self ), profile );
974
- Object dict = lib .hasDict (self ) ? lib .getDict (self ) : PNone .NONE ;
958
+ Object dict = lookupAttr .execute (frame , self , __DICT__ );
959
+ if (PGuards .isNoValue (dict ) || sizeNode .execute (frame , dict ) <= 0 ) {
960
+ dict = PNone .NONE ;
961
+ }
975
962
Object it = lib .getIterator (self );
976
963
PTuple emptyTuple = factory ().createEmptyTuple ();
977
964
int maxLength = self .getMaxLength ();
0 commit comments