43
43
import com .oracle .graal .python .builtins .objects .object .PythonBuiltinObject ;
44
44
import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
45
45
import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
46
- import com .oracle .graal .python .nodes .SpecialMethodNames ;
47
46
import com .oracle .graal .python .nodes .attributes .ReadAttributeFromDynamicObjectNode ;
48
- import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode .LookupAndCallUnaryDynamicNode ;
49
47
import com .oracle .graal .python .nodes .util .CastToByteNode ;
50
- import com .oracle .graal .python .nodes .util .CastToJavaIntNode ;
51
48
import com .oracle .truffle .api .dsl .Cached ;
52
49
import com .oracle .truffle .api .dsl .Cached .Shared ;
50
+ import com .oracle .truffle .api .library .CachedLibrary ;
53
51
import com .oracle .truffle .api .library .ExportLibrary ;
54
52
import com .oracle .truffle .api .library .ExportMessage ;
55
53
@@ -70,21 +68,19 @@ boolean isBuffer() {
70
68
@ ExportMessage
71
69
int getBufferLength (
72
70
@ Shared ("readNativeMemoryViewNode" ) @ Cached ReadAttributeFromDynamicObjectNode readNativeMemoryViewNode ,
73
- @ Shared ("lenNode" ) @ Cached LookupAndCallUnaryDynamicNode lenNode ,
74
- @ Shared ("castToIntNode" ) @ Cached CastToJavaIntNode castToIntNode ) {
71
+ @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ) {
75
72
Object nativeMemoryViewObject = readNativeMemoryViewNode .execute (getStorage (), C_MEMORYVIEW );
76
- return castToIntNode . execute ( lenNode . executeObject ( nativeMemoryViewObject , SpecialMethodNames . __LEN__ ) );
73
+ return lib . length ( nativeMemoryViewObject );
77
74
}
78
75
79
76
@ ExportMessage
80
77
byte [] getBufferBytes (
81
78
@ Shared ("readNativeMemoryViewNode" ) @ Cached ReadAttributeFromDynamicObjectNode readNativeMemoryViewNode ,
82
- @ Shared ("lenNode" ) @ Cached LookupAndCallUnaryDynamicNode lenNode ,
83
- @ Shared ("castToIntNode" ) @ Cached CastToJavaIntNode castToIntNode ,
79
+ @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ,
84
80
@ Cached PInteropSubscriptNode subscriptNode ,
85
81
@ Cached CastToByteNode castToByteNode ) {
86
82
Object nativeMemoryViewObject = readNativeMemoryViewNode .execute (getStorage (), C_MEMORYVIEW );
87
- int len = castToIntNode . execute ( lenNode . executeObject ( nativeMemoryViewObject , SpecialMethodNames . __LEN__ ) );
83
+ int len = lib . length ( nativeMemoryViewObject );
88
84
byte [] data = new byte [len ];
89
85
for (int i = 0 ; i < data .length ; i ++) {
90
86
data [i ] = castToByteNode .execute (null , subscriptNode .execute (nativeMemoryViewObject , i ));
0 commit comments