62
62
import com .oracle .graal .python .builtins .objects .PNotImplemented ;
63
63
import com .oracle .graal .python .builtins .objects .bytes .BytesBuiltinsFactory .BytesLikeNoGeneralizationNodeGen ;
64
64
import com .oracle .graal .python .builtins .objects .common .IndexNodes .NormalizeIndexNode ;
65
- import com .oracle .graal .python .builtins .objects .common .SequenceNodes ;
66
65
import com .oracle .graal .python .builtins .objects .common .SequenceNodes .GetObjectArrayNode ;
67
- import com .oracle .graal .python .builtins .objects .common .SequenceNodes .GetSequenceStorageNode ;
68
66
import com .oracle .graal .python .builtins .objects .common .SequenceNodesFactory .GetObjectArrayNodeGen ;
69
67
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes ;
70
68
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .GenNodeSupplier ;
@@ -182,14 +180,13 @@ public abstract static class EqNode extends PythonBinaryBuiltinNode {
182
180
@ Child private SequenceStorageNodes .CmpNode eqNode ;
183
181
184
182
@ Specialization
185
- boolean eq (VirtualFrame frame , PBytesLike self , PBytesLike other ,
186
- @ Cached GetSequenceStorageNode getStorage ) {
187
- return getEqNode ().execute (frame , getStorage .execute (self ), getStorage .execute (other ));
183
+ boolean eq (VirtualFrame frame , PBytesLike self , PBytesLike other ) {
184
+ return getEqNode ().execute (frame , self .getSequenceStorage (), other .getSequenceStorage ());
188
185
}
189
186
190
187
@ Fallback
191
188
public Object eq (Object self , @ SuppressWarnings ("unused" ) Object other ) {
192
- if (PGuards . isBytes ( self ) ) {
189
+ if (self instanceof PBytesLike ) {
193
190
return PNotImplemented .NOT_IMPLEMENTED ;
194
191
}
195
192
throw raise (TypeError , ErrorMessages .DESCRIPTOR_REQUIRES_OBJ , "__eq__" , "bytes-like" , self );
@@ -211,14 +208,13 @@ public abstract static class NeNode extends PythonBinaryBuiltinNode {
211
208
@ Child SequenceStorageNodes .CmpNode eqNode ;
212
209
213
210
@ Specialization
214
- boolean ne (VirtualFrame frame , PBytesLike self , PBytesLike other ,
215
- @ Cached GetSequenceStorageNode getStorage ) {
216
- return !getEqNode ().execute (frame , getStorage .execute (self ), getStorage .execute (other ));
211
+ boolean ne (VirtualFrame frame , PBytesLike self , PBytesLike other ) {
212
+ return !getEqNode ().execute (frame , self .getSequenceStorage (), other .getSequenceStorage ());
217
213
}
218
214
219
215
@ Fallback
220
216
Object ne (Object self , @ SuppressWarnings ("unused" ) Object other ) {
221
- if (PGuards . isBytes ( self ) ) {
217
+ if (self instanceof PBytesLike ) {
222
218
return PNotImplemented .NOT_IMPLEMENTED ;
223
219
}
224
220
throw raise (TypeError , ErrorMessages .DESCRIPTOR_REQUIRES_OBJ , "__ne__" , "bytes-like" , self );
@@ -345,9 +341,8 @@ public static boolean doByte(PBytes byteArray) {
345
341
346
342
@ Specialization
347
343
static boolean doLen (PBytesLike operand ,
348
- @ Cached ("create()" ) SequenceStorageNodes .LenNode lenNode ,
349
- @ Cached GetSequenceStorageNode getSelfStorage ) {
350
- return lenNode .execute (getSelfStorage .execute (operand )) != 0 ;
344
+ @ Cached ("create()" ) SequenceStorageNodes .LenNode lenNode ) {
345
+ return lenNode .execute (operand .getSequenceStorage ()) != 0 ;
351
346
}
352
347
353
348
@ Fallback
@@ -362,17 +357,15 @@ public abstract static class AddNode extends PythonBinaryBuiltinNode {
362
357
363
358
@ Specialization
364
359
public Object add (PBytes left , PBytesLike right ,
365
- @ Cached ("create()" ) SequenceStorageNodes .ConcatNode concatNode ,
366
- @ Cached GetSequenceStorageNode getStorage ) {
367
- ByteSequenceStorage res = (ByteSequenceStorage ) concatNode .execute (left .getSequenceStorage (), getStorage .execute (right ));
360
+ @ Cached ("create()" ) SequenceStorageNodes .ConcatNode concatNode ) {
361
+ ByteSequenceStorage res = (ByteSequenceStorage ) concatNode .execute (left .getSequenceStorage (), right .getSequenceStorage ());
368
362
return factory ().createBytes (res );
369
363
}
370
364
371
365
@ Specialization
372
366
public Object add (PByteArray self , PBytesLike other ,
373
- @ Cached SequenceStorageNodes .ConcatNode concatNode ,
374
- @ Cached GetSequenceStorageNode getStorage ) {
375
- SequenceStorage res = concatNode .execute (self .getSequenceStorage (), getStorage .execute (other ));
367
+ @ Cached SequenceStorageNodes .ConcatNode concatNode ) {
368
+ SequenceStorage res = concatNode .execute (self .getSequenceStorage (), other .getSequenceStorage ());
376
369
return factory ().createByteArray (res );
377
370
}
378
371
@@ -488,7 +481,7 @@ Object doByteArray(VirtualFrame frame, PByteArray self, Object right,
488
481
489
482
private byte [] format (VirtualFrame frame , Object self , Object right , PythonObjectLibrary selfLib , LookupAndCallBinaryNode getItemNode , TupleBuiltins .GetItemNode getTupleItemNode ,
490
483
PythonContext context ) {
491
- assert self instanceof PBytes || self instanceof PByteArray ;
484
+ assert self instanceof PBytesLike ;
492
485
Object state = IndirectCallContext .enter (frame , context , this );
493
486
try {
494
487
BytesFormatProcessor formatter = new BytesFormatProcessor (context .getCore (), getItemNode , getTupleItemNode , selfLib .getBufferBytes (self ));
@@ -586,9 +579,8 @@ public Object doGeneric(Object self, Object arg) {
586
579
public abstract static class LenNode extends PythonUnaryBuiltinNode {
587
580
@ Specialization
588
581
public static int len (PBytesLike self ,
589
- @ Cached ("create()" ) SequenceStorageNodes .LenNode lenNode ,
590
- @ Cached GetSequenceStorageNode getSelfStorage ) {
591
- return lenNode .execute (getSelfStorage .execute (self ));
582
+ @ Cached ("create()" ) SequenceStorageNodes .LenNode lenNode ) {
583
+ return lenNode .execute (self .getSequenceStorage ());
592
584
}
593
585
}
594
586
@@ -607,23 +599,20 @@ private int getLength(SequenceStorage s) {
607
599
608
600
@ Specialization
609
601
boolean contains (VirtualFrame frame , PBytesLike self , PBytesLike other ,
610
- @ Cached ("create()" ) BytesNodes .FindNode findNode ,
611
- @ Shared ("getSelfStorage" ) @ Cached GetSequenceStorageNode getSelfStorage ) {
612
- return findNode .execute (frame , self , other , 0 , getLength (getSelfStorage .execute (self ))) != -1 ;
602
+ @ Cached ("create()" ) BytesNodes .FindNode findNode ) {
603
+ return findNode .execute (frame , self , other , 0 , getLength (self .getSequenceStorage ())) != -1 ;
613
604
}
614
605
615
606
@ Specialization
616
607
boolean contains (VirtualFrame frame , PBytesLike self , int other ,
617
- @ Cached ("create()" ) BytesNodes .FindNode findNode ,
618
- @ Shared ("getSelfStorage" ) @ Cached GetSequenceStorageNode getSelfStorage ) {
619
- return findNode .execute (frame , self , other , 0 , getLength (getSelfStorage .execute (self ))) != -1 ;
608
+ @ Cached ("create()" ) BytesNodes .FindNode findNode ) {
609
+ return findNode .execute (frame , self , other , 0 , getLength (self .getSequenceStorage ())) != -1 ;
620
610
}
621
611
622
612
@ Specialization
623
613
boolean contains (VirtualFrame frame , PBytesLike self , long other ,
624
- @ Cached ("create()" ) BytesNodes .FindNode findNode ,
625
- @ Shared ("getSelfStorage" ) @ Cached GetSequenceStorageNode getSelfStorage ) {
626
- return findNode .execute (frame , self , other , 0 , getLength (getSelfStorage .execute (self ))) != -1 ;
614
+ @ Cached ("create()" ) BytesNodes .FindNode findNode ) {
615
+ return findNode .execute (frame , self , other , 0 , getLength (self .getSequenceStorage ())) != -1 ;
627
616
}
628
617
629
618
@ Specialization (guards = {"!isBytes(other)" })
@@ -878,17 +867,15 @@ public abstract static class ByteArrayIndexNode extends PythonQuaternaryBuiltinN
878
867
@ Specialization
879
868
int index (VirtualFrame frame , PBytesLike byteArray , Object arg , @ SuppressWarnings ("unused" ) PNone start , @ SuppressWarnings ("unused" ) PNone end ,
880
869
@ Shared ("len" ) @ Cached SequenceStorageNodes .LenNode lenNode ,
881
- @ Shared ("storage" ) @ Cached SequenceNodes .GetSequenceStorageNode getStorageNode ,
882
870
@ Shared ("findNode" ) @ Cached ("create()" ) BytesNodes .FindNode findNode ) {
883
- return checkResult (findNode .execute (frame , byteArray , arg , 0 , lenNode .execute (getStorageNode . execute ( byteArray ))));
871
+ return checkResult (findNode .execute (frame , byteArray , arg , 0 , lenNode .execute (byteArray . getSequenceStorage ( ))));
884
872
}
885
873
886
874
@ Specialization (guards = {"!isPNone(start)" })
887
875
int indexWithStart (VirtualFrame frame , PBytesLike byteArray , Object arg , Object start , @ SuppressWarnings ("unused" ) PNone end ,
888
- @ Shared ("storage" ) @ Cached SequenceNodes .GetSequenceStorageNode getStorageNode ,
889
876
@ Shared ("len" ) @ Cached SequenceStorageNodes .LenNode lenNode ,
890
877
@ Shared ("findNode" ) @ Cached ("create()" ) BytesNodes .FindNode findNode ) {
891
- return checkResult (findNode .execute (frame , byteArray , arg , start , lenNode .execute (getStorageNode . execute ( byteArray ))));
878
+ return checkResult (findNode .execute (frame , byteArray , arg , start , lenNode .execute (byteArray . getSequenceStorage ( ))));
892
879
}
893
880
894
881
@ Specialization (guards = {"!isPNone(end)" })
@@ -943,25 +930,22 @@ abstract static class FindNode extends PythonBuiltinNode {
943
930
@ Specialization
944
931
static int find (VirtualFrame frame , PBytesLike self , Object sub , @ SuppressWarnings ("unused" ) PNone start , @ SuppressWarnings ("unused" ) PNone end ,
945
932
@ Shared ("lenNode" ) @ Cached SequenceStorageNodes .LenNode lenNode ,
946
- @ Shared ("findNode" ) @ Cached BytesNodes .FindNode findNode ,
947
- @ Cached GetSequenceStorageNode getSelfStorage ) {
948
- return find (frame , self , sub , 0 , lenNode .execute (getSelfStorage .execute (self )), findNode );
933
+ @ Shared ("findNode" ) @ Cached BytesNodes .FindNode findNode ) {
934
+ return find (frame , self , sub , 0 , lenNode .execute (self .getSequenceStorage ()), findNode );
949
935
}
950
936
951
937
@ Specialization
952
938
static int find (VirtualFrame frame , PBytesLike self , Object sub , int start , @ SuppressWarnings ("unused" ) PNone end ,
953
939
@ Shared ("lenNode" ) @ Cached SequenceStorageNodes .LenNode lenNode ,
954
- @ Shared ("findNode" ) @ Cached BytesNodes .FindNode findNode ,
955
- @ Cached GetSequenceStorageNode getSelfStorage ) {
956
- return find (frame , self , sub , start , lenNode .execute (getSelfStorage .execute (self )), findNode );
940
+ @ Shared ("findNode" ) @ Cached BytesNodes .FindNode findNode ) {
941
+ return find (frame , self , sub , start , lenNode .execute (self .getSequenceStorage ()), findNode );
957
942
}
958
943
959
944
@ Specialization
960
945
static int find (VirtualFrame frame , PBytesLike self , Object sub , Object start , @ SuppressWarnings ("unused" ) PNone end ,
961
946
@ Shared ("lenNode" ) @ Cached SequenceStorageNodes .LenNode lenNode ,
962
- @ Shared ("findNode" ) @ Cached BytesNodes .FindNode findNode ,
963
- @ Cached GetSequenceStorageNode getSelfStorage ) {
964
- return find (frame , self , sub , start , lenNode .execute (getSelfStorage .execute (self )), findNode );
947
+ @ Shared ("findNode" ) @ Cached BytesNodes .FindNode findNode ) {
948
+ return find (frame , self , sub , start , lenNode .execute (self .getSequenceStorage ()), findNode );
965
949
}
966
950
967
951
@ Specialization
0 commit comments