Skip to content

Commit 8936679

Browse files
committed
replace __len__ call in PySequenceArrayWrapper
1 parent 5b4d738 commit 8936679

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PySequenceArrayWrapper.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@
5757
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.NoGeneralizationNode;
5858
import com.oracle.graal.python.builtins.objects.list.PList;
5959
import com.oracle.graal.python.builtins.objects.mmap.PMMap;
60+
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
6061
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
6162
import com.oracle.graal.python.nodes.SpecialMethodNames;
6263
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
6364
import com.oracle.graal.python.nodes.call.CallNode;
64-
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.LookupAndCallUnaryDynamicNode;
6565
import com.oracle.graal.python.nodes.truffle.PythonTypes;
6666
import com.oracle.graal.python.nodes.util.CoerceToJavaLongNode;
67+
import com.oracle.graal.python.runtime.PythonOptions;
6768
import com.oracle.graal.python.runtime.sequence.PSequence;
6869
import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
6970
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
@@ -138,9 +139,8 @@ public boolean equals(Object obj) {
138139
@ExportMessage
139140
final long getArraySize(
140141
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
141-
@Shared("callLenNode") @Cached LookupAndCallUnaryDynamicNode callLenNode,
142-
@Shared("castToLongNode") @Cached CoerceToJavaLongNode castToLongNode) {
143-
return castToLongNode.execute(callLenNode.executeObject(lib.getDelegate(this), SpecialMethodNames.__LEN__));
142+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib) {
143+
return objectLib.length(lib.getDelegate(this));
144144
}
145145

146146
@ExportMessage
@@ -156,13 +156,16 @@ final Object readArrayElement(long index,
156156
return readArrayItemNode.execute(lib.getDelegate(this), index);
157157
}
158158

159+
static int getCallSiteInlineCacheMaxDepth() {
160+
return PythonOptions.getCallSiteInlineCacheMaxDepth();
161+
}
162+
159163
@ExportMessage
160164
final boolean isArrayElementReadable(long identifier,
161165
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
162-
@Shared("callLenNode") @Cached LookupAndCallUnaryDynamicNode callLenNode,
163-
@Shared("castToLongNode") @Cached CoerceToJavaLongNode castToLongNode) {
166+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib) {
164167
// also include the implicit null-terminator
165-
return 0 <= identifier && identifier <= getArraySize(lib, callLenNode, castToLongNode);
168+
return 0 <= identifier && identifier <= getArraySize(lib, objectLib);
166169
}
167170

168171
@ImportStatic({SpecialMethodNames.class, PySequenceArrayWrapper.class})
@@ -302,25 +305,22 @@ public void removeArrayElement(@SuppressWarnings("unused") long index) throws Un
302305
@ExportMessage
303306
public boolean isArrayElementModifiable(long index,
304307
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
305-
@Shared("callLenNode") @Cached LookupAndCallUnaryDynamicNode callLenNode,
306-
@Shared("castToLongNode") @Cached CoerceToJavaLongNode castToLongNode) {
307-
return 0 <= index && index <= getArraySize(lib, callLenNode, castToLongNode);
308+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib) {
309+
return 0 <= index && index <= getArraySize(lib, objectLib);
308310
}
309311

310312
@ExportMessage
311313
public boolean isArrayElementInsertable(long index,
312314
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
313-
@Shared("callLenNode") @Cached LookupAndCallUnaryDynamicNode callLenNode,
314-
@Shared("castToLongNode") @Cached CoerceToJavaLongNode castToLongNode) {
315-
return 0 <= index && index <= getArraySize(lib, callLenNode, castToLongNode);
315+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib) {
316+
return 0 <= index && index <= getArraySize(lib, objectLib);
316317
}
317318

318319
@ExportMessage
319320
public boolean isArrayElementRemovable(long index,
320321
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
321-
@Shared("callLenNode") @Cached LookupAndCallUnaryDynamicNode callLenNode,
322-
@Shared("castToLongNode") @Cached CoerceToJavaLongNode castToLongNode) {
323-
return 0 <= index && index <= getArraySize(lib, callLenNode, castToLongNode);
322+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib) {
323+
return 0 <= index && index <= getArraySize(lib, objectLib);
324324
}
325325

326326
@GenerateUncached

0 commit comments

Comments
 (0)