Skip to content

Commit 50dad63

Browse files
committed
ModuleBuiltins: __dir__ use ConstructListNode (from dict)
1 parent a376175 commit 50dad63

File tree

1 file changed

+3
-14
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module

1 file changed

+3
-14
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INIT__;
5353
import static com.oracle.graal.python.runtime.exception.PythonErrorType.AttributeError;
5454

55-
import java.util.ArrayList;
56-
import java.util.Iterator;
5755
import java.util.List;
5856

5957
import com.oracle.graal.python.builtins.Builtin;
@@ -72,6 +70,7 @@
7270
import com.oracle.graal.python.nodes.ErrorMessages;
7371
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
7472
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
73+
import com.oracle.graal.python.nodes.builtins.ListNodes;
7574
import com.oracle.graal.python.nodes.call.CallNode;
7675
import com.oracle.graal.python.nodes.expression.CoerceToBooleanNode;
7776
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -147,6 +146,7 @@ Object dir(PythonModule self,
147146
@Cached CastToJavaStringNode castToJavaStringNode,
148147
@Cached IsBuiltinClassProfile isDictProfile,
149148
@Cached HashingCollectionNodes.GetDictStorageNode getDictStorageNode,
149+
@Cached ListNodes.ConstructListNode constructListNode,
150150
@Cached CallNode callNode,
151151
@CachedLibrary(limit = "1") HashingStorageLibrary hashLib,
152152
@CachedLibrary(limit = "1") PythonObjectLibrary pol) {
@@ -157,25 +157,14 @@ Object dir(PythonModule self,
157157
if (dirFunc != null) {
158158
return callNode.execute(dirFunc);
159159
} else {
160-
return factory().createList(exhaustIterator(hashLib.keys(dictStorage)));
160+
return constructListNode.execute(dict);
161161
}
162162
} else {
163163
String name = getName(self, pol, hashLib, castToJavaStringNode);
164164
throw this.raise(PythonBuiltinClassType.TypeError, "%s.__dict__ is not a dictionary", name);
165165
}
166166
}
167167

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-
179168
private String getName(PythonModule self, PythonObjectLibrary pol, HashingStorageLibrary hashLib, CastToJavaStringNode castToJavaStringNode) {
180169
PHashingCollection dict = pol.getDict(self);
181170
if (dict != null) {

0 commit comments

Comments
 (0)