33
33
class Block (object ):
34
34
__slots__ = ('leftlink' , 'rightlink' , 'data' )
35
35
36
+ @__graalpython__ .builtin_method
36
37
def __init__ (self , leftlink , rightlink ):
37
38
self .leftlink = leftlink
38
39
self .rightlink = rightlink
@@ -68,6 +69,7 @@ def _next_or_none(_iter):
68
69
69
70
70
71
class deque (object ):
72
+ @__graalpython__ .builtin_method
71
73
def __init__ (self , iterable = None , maxlen = None ):
72
74
if maxlen is None :
73
75
self ._maxlen = sys .maxsize
@@ -90,6 +92,7 @@ def __init__(self, iterable=None, maxlen=None):
90
92
self .extend (iterable )
91
93
92
94
def synchronized (fun ):
95
+ @__graalpython__ .builtin_method
93
96
def fun_synchronized (self , * args ):
94
97
with self ._mutex :
95
98
return fun (self , * args )
@@ -121,14 +124,17 @@ def pop(self):
121
124
self ._modified ()
122
125
return obj
123
126
127
+ @__graalpython__ .builtin_method
124
128
def _modified (self ):
125
129
self ._lock = None
126
130
131
+ @__graalpython__ .builtin_method
127
132
def _getlock (self ):
128
133
if self ._lock is None :
129
134
self ._lock = Lock ()
130
135
return self ._lock
131
136
137
+ @__graalpython__ .builtin_method
132
138
def _checklock (self , lock ):
133
139
if lock is not self ._lock :
134
140
raise RuntimeError ("deque mutated during iteration" )
@@ -225,23 +231,29 @@ def extend(self, iterable):
225
231
break
226
232
self .append (obj )
227
233
234
+ @__graalpython__ .builtin_method
228
235
def __iadd__ (self , other ):
229
236
return _add (self , other )
230
237
238
+ @__graalpython__ .builtin_method
231
239
def __add__ (self , other ):
232
240
if not isinstance (other , deque ):
233
241
raise TypeError ("can only concatenate deque (not '%s') to deque" % (type (other )))
234
242
return _add (deque (self , maxlen = self .maxlen ), other )
235
243
244
+ @__graalpython__ .builtin_method
236
245
def __imul__ (self , times ):
237
246
return _mul (self , times )
238
247
248
+ @__graalpython__ .builtin_method
239
249
def __mul__ (self , times ):
240
250
return _mul (deque (self , maxlen = self .maxlen ), times )
241
251
252
+ @__graalpython__ .builtin_method
242
253
def __rmul__ (self , times ):
243
254
return _mul (deque (self , maxlen = self .maxlen ), times )
244
255
256
+ @__graalpython__ .builtin_method
245
257
def __hash__ (self ):
246
258
raise TypeError ("unhashable type: '{}'" .format (type (self ).__name__ ))
247
259
@@ -343,16 +355,20 @@ def rotate(self, n=1):
343
355
self .append (self .popleft ())
344
356
i -= 1
345
357
358
+ @__graalpython__ .builtin_method
346
359
def __iter__ (self ):
347
360
return _DequeIter (self )
348
361
362
+ @__graalpython__ .builtin_method
349
363
def __reversed__ (self ):
350
364
"""Return a reverse iterator over the deque."""
351
365
return _DequeRevIter (self )
352
366
367
+ @__graalpython__ .builtin_method
353
368
def __len__ (self ):
354
369
return self .len
355
370
371
+ @__graalpython__ .builtin_method
356
372
def __repr__ (self ):
357
373
# TODO: this does not handle infinite repr recursive calls ... (GR-10763)
358
374
try :
@@ -405,6 +421,7 @@ def __compare__(self, other, op):
405
421
return x1 >= x2
406
422
assert False , "bad value for op"
407
423
424
+ @__graalpython__ .builtin_method
408
425
def __contains__ (self , v ):
409
426
lock = self ._getlock ()
410
427
n = self .len
@@ -427,13 +444,15 @@ def __contains__(self, v):
427
444
428
445
return False
429
446
447
+ @__graalpython__ .builtin_method
430
448
def _norm_index (self , idx , force_index_to_zero = True ):
431
449
if idx < 0 :
432
450
idx += self .len
433
451
if idx < 0 and force_index_to_zero :
434
452
idx = 0
435
453
return idx
436
454
455
+ @__graalpython__ .builtin_method
437
456
def _check_index (self , idx ):
438
457
if idx < 0 or idx >= self .len :
439
458
raise IndexError ("deque index out of range" )
@@ -482,24 +501,31 @@ def index(self, v, start=0, stop=None):
482
501
483
502
raise ValueError ("%s is not in deque" % v )
484
503
504
+ @__graalpython__ .builtin_method
485
505
def __lt__ (self , other ):
486
506
return self .__compare__ (other , 'lt' )
487
507
508
+ @__graalpython__ .builtin_method
488
509
def __le__ (self , other ):
489
510
return self .__compare__ (other , 'le' )
490
511
512
+ @__graalpython__ .builtin_method
491
513
def __eq__ (self , other ):
492
514
return self .__compare__ (other , 'eq' )
493
515
516
+ @__graalpython__ .builtin_method
494
517
def __ne__ (self , other ):
495
518
return self .__compare__ (other , 'ne' )
496
519
520
+ @__graalpython__ .builtin_method
497
521
def __gt__ (self , other ):
498
522
return self .__compare__ (other , 'gt' )
499
523
524
+ @__graalpython__ .builtin_method
500
525
def __ge__ (self , other ):
501
526
return self .__compare__ (other , 'ge' )
502
527
528
+ @__graalpython__ .builtin_method
503
529
def _locate (self , i ):
504
530
if i < (self .len >> 1 ):
505
531
i += self .leftindex
@@ -517,25 +543,29 @@ def _locate(self, i):
517
543
assert i >= 0
518
544
return b , i
519
545
546
+ @__graalpython__ .builtin_method
520
547
def delitem (self , i ):
521
548
# delitem() implemented in terms of rotate for simplicity and
522
549
# reasonable performance near the end points.
523
550
self .rotate (- i )
524
551
self .popleft ()
525
552
self .rotate (i )
526
553
554
+ @__graalpython__ .builtin_method
527
555
def __getitem__ (self , idx ):
528
556
idx = self ._norm_index (idx )
529
557
self ._check_index (idx )
530
558
b , i = self ._locate (idx )
531
559
return b .data [i ]
532
560
561
+ @__graalpython__ .builtin_method
533
562
def __setitem__ (self , idx , value ):
534
563
idx = self ._norm_index (idx , force_index_to_zero = False )
535
564
self ._check_index (idx )
536
565
b , i = self ._locate (idx )
537
566
b .data [i ] = value
538
567
568
+ @__graalpython__ .builtin_method
539
569
def __delitem__ (self , idx ):
540
570
idx = self ._norm_index (idx , force_index_to_zero = False )
541
571
self ._check_index (idx )
@@ -549,9 +579,11 @@ def copy(self):
549
579
else :
550
580
return deque (self , self .maxlen )
551
581
582
+ @__graalpython__ .builtin_method
552
583
def __copy__ (self ):
553
584
return self .copy ()
554
585
586
+ @__graalpython__ .builtin_method
555
587
def __reduce__ (self ):
556
588
"""Return state information for pickling."""
557
589
_type = type (self )
@@ -581,6 +613,7 @@ def maxlen(self):
581
613
582
614
583
615
class _DequeIter (object ):
616
+ @__graalpython__ .builtin_method
584
617
def __init__ (self , dq ):
585
618
self ._deque = dq
586
619
self .block = dq .leftblock
@@ -589,12 +622,15 @@ def __init__(self, dq):
589
622
self .lock = dq ._getlock ()
590
623
assert self .index >= 0
591
624
625
+ @__graalpython__ .builtin_method
592
626
def __iter__ (self ):
593
627
return self
594
628
629
+ @__graalpython__ .builtin_method
595
630
def __len__ (self ):
596
631
return self .counter
597
632
633
+ @__graalpython__ .builtin_method
598
634
def __next__ (self ):
599
635
if self .lock is not self ._deque ._lock :
600
636
self .counter = 0
@@ -613,6 +649,7 @@ def __next__(self):
613
649
614
650
615
651
class _DequeRevIter (object ):
652
+ @__graalpython__ .builtin_method
616
653
def __init__ (self , dq ):
617
654
self ._deque = dq
618
655
self .block = dq .rightblock
@@ -621,12 +658,15 @@ def __init__(self, dq):
621
658
self .lock = dq ._getlock ()
622
659
assert self .index >= 0
623
660
661
+ @__graalpython__ .builtin_method
624
662
def __iter__ (self ):
625
663
return self
626
664
665
+ @__graalpython__ .builtin_method
627
666
def __len__ (self ):
628
667
return self .counter
629
668
669
+ @__graalpython__ .builtin_method
630
670
def __next__ (self ):
631
671
if self .lock is not self ._deque ._lock :
632
672
self .counter = 0
@@ -645,22 +685,26 @@ def __next__(self):
645
685
646
686
647
687
class defaultdict (dict ):
688
+ @__graalpython__ .builtin_method
648
689
def __init__ (self , default_factory = None , * args , ** kwds ):
649
690
dict .__init__ (self , * args , ** kwds )
650
691
if (default_factory is None or callable (default_factory )):
651
692
self .default_factory = default_factory
652
693
else :
653
694
raise TypeError ("first argument must be callable or None" )
654
695
696
+ @__graalpython__ .builtin_method
655
697
def __missing__ (self , key ):
656
698
if self .default_factory is None :
657
699
raise KeyError (key )
658
700
self [key ] = value = self .default_factory ()
659
701
return value
660
702
703
+ @__graalpython__ .builtin_method
661
704
def __repr__ (self ):
662
705
return "%s(%r, %s)" % (type (self ).__name__ , self .default_factory , dict .__repr__ (self ))
663
706
707
+ @__graalpython__ .builtin_method
664
708
def copy (self ):
665
709
cp = defaultdict (default_factory = self .default_factory )
666
710
for k ,v in self .items ():
0 commit comments