Skip to content

Commit 5b4d738

Browse files
committed
replace __len__ call in memoryview messages
1 parent ce7f291 commit 5b4d738

File tree

1 file changed

+5
-9
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview

1 file changed

+5
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/PMemoryView.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@
4343
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
4444
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
4545
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
46-
import com.oracle.graal.python.nodes.SpecialMethodNames;
4746
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode;
48-
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.LookupAndCallUnaryDynamicNode;
4947
import com.oracle.graal.python.nodes.util.CastToByteNode;
50-
import com.oracle.graal.python.nodes.util.CastToJavaIntNode;
5148
import com.oracle.truffle.api.dsl.Cached;
5249
import com.oracle.truffle.api.dsl.Cached.Shared;
50+
import com.oracle.truffle.api.library.CachedLibrary;
5351
import com.oracle.truffle.api.library.ExportLibrary;
5452
import com.oracle.truffle.api.library.ExportMessage;
5553

@@ -70,21 +68,19 @@ boolean isBuffer() {
7068
@ExportMessage
7169
int getBufferLength(
7270
@Shared("readNativeMemoryViewNode") @Cached ReadAttributeFromDynamicObjectNode readNativeMemoryViewNode,
73-
@Shared("lenNode") @Cached LookupAndCallUnaryDynamicNode lenNode,
74-
@Shared("castToIntNode") @Cached CastToJavaIntNode castToIntNode) {
71+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
7572
Object nativeMemoryViewObject = readNativeMemoryViewNode.execute(getStorage(), C_MEMORYVIEW);
76-
return castToIntNode.execute(lenNode.executeObject(nativeMemoryViewObject, SpecialMethodNames.__LEN__));
73+
return lib.length(nativeMemoryViewObject);
7774
}
7875

7976
@ExportMessage
8077
byte[] getBufferBytes(
8178
@Shared("readNativeMemoryViewNode") @Cached ReadAttributeFromDynamicObjectNode readNativeMemoryViewNode,
82-
@Shared("lenNode") @Cached LookupAndCallUnaryDynamicNode lenNode,
83-
@Shared("castToIntNode") @Cached CastToJavaIntNode castToIntNode,
79+
@CachedLibrary(limit = "1") PythonObjectLibrary lib,
8480
@Cached PInteropSubscriptNode subscriptNode,
8581
@Cached CastToByteNode castToByteNode) {
8682
Object nativeMemoryViewObject = readNativeMemoryViewNode.execute(getStorage(), C_MEMORYVIEW);
87-
int len = castToIntNode.execute(lenNode.executeObject(nativeMemoryViewObject, SpecialMethodNames.__LEN__));
83+
int len = lib.length(nativeMemoryViewObject);
8884
byte[] data = new byte[len];
8985
for (int i = 0; i < data.length; i++) {
9086
data[i] = castToByteNode.execute(null, subscriptNode.execute(nativeMemoryViewObject, i));

0 commit comments

Comments
 (0)