52
52
import static com .oracle .graal .python .nodes .SpecialMethodNames .__INIT__ ;
53
53
import static com .oracle .graal .python .runtime .exception .PythonErrorType .AttributeError ;
54
54
55
- import java .util .ArrayList ;
56
- import java .util .Iterator ;
57
55
import java .util .List ;
58
56
59
57
import com .oracle .graal .python .builtins .Builtin ;
72
70
import com .oracle .graal .python .nodes .ErrorMessages ;
73
71
import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
74
72
import com .oracle .graal .python .nodes .attributes .WriteAttributeToObjectNode ;
73
+ import com .oracle .graal .python .nodes .builtins .ListNodes ;
75
74
import com .oracle .graal .python .nodes .call .CallNode ;
76
75
import com .oracle .graal .python .nodes .expression .CoerceToBooleanNode ;
77
76
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
@@ -147,6 +146,7 @@ Object dir(PythonModule self,
147
146
@ Cached CastToJavaStringNode castToJavaStringNode ,
148
147
@ Cached IsBuiltinClassProfile isDictProfile ,
149
148
@ Cached HashingCollectionNodes .GetDictStorageNode getDictStorageNode ,
149
+ @ Cached ListNodes .ConstructListNode constructListNode ,
150
150
@ Cached CallNode callNode ,
151
151
@ CachedLibrary (limit = "1" ) HashingStorageLibrary hashLib ,
152
152
@ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
@@ -157,25 +157,14 @@ Object dir(PythonModule self,
157
157
if (dirFunc != null ) {
158
158
return callNode .execute (dirFunc );
159
159
} else {
160
- return factory (). createList ( exhaustIterator ( hashLib . keys ( dictStorage )) );
160
+ return constructListNode . execute ( dict );
161
161
}
162
162
} else {
163
163
String name = getName (self , pol , hashLib , castToJavaStringNode );
164
164
throw this .raise (PythonBuiltinClassType .TypeError , "%s.__dict__ is not a dictionary" , name );
165
165
}
166
166
}
167
167
168
- private static <T > Object [] exhaustIterator (Iterable <T > iterable ) {
169
- return exhaustIterator (iterable .iterator ());
170
- }
171
-
172
- @ CompilerDirectives .TruffleBoundary
173
- private static <T > Object [] exhaustIterator (Iterator <T > iterator ) {
174
- ArrayList <T > values = new ArrayList <>();
175
- iterator .forEachRemaining (values ::add );
176
- return values .toArray ();
177
- }
178
-
179
168
private String getName (PythonModule self , PythonObjectLibrary pol , HashingStorageLibrary hashLib , CastToJavaStringNode castToJavaStringNode ) {
180
169
PHashingCollection dict = pol .getDict (self );
181
170
if (dict != null ) {
0 commit comments