@@ -298,6 +298,7 @@ def bound_collection_from_inst(
298
298
)
299
299
return new_tokens
300
300
301
+ # Move to scanner35?
301
302
def bound_map_from_inst_35 (
302
303
self , insts : list , next_tokens : list , t : Token , i : int
303
304
) -> Optional [list ]:
@@ -389,92 +390,6 @@ def bound_map_from_inst_35(
389
390
)
390
391
return new_tokens
391
392
392
- def bound_map_from_inst_pre35 (
393
- self , insts : list , next_tokens : list , t : Token , i : int
394
- ):
395
- """
396
- Try to a sequence of instruction that ends with a BUILD_MAP into
397
- a sequence that can be parsed much faster, but inserting the
398
- token boundary at the beginning of the sequence.
399
- """
400
- count = t .attr
401
- assert isinstance (count , int )
402
-
403
- # For small lists don't bother
404
- if count < 10 :
405
- return None
406
-
407
- # Older Python BUILD_MAP argument's count is a
408
- # key and value pair and STORE_MAP. So it is multiplied by three.
409
- collection_end = i + 1 + count * 3
410
-
411
- for j in range (i + 1 , collection_end , 3 ):
412
- if insts [j ].opname not in ("LOAD_CONST" ,):
413
- return None
414
- if insts [j + 1 ].opname not in ("LOAD_CONST" ,):
415
- return None
416
- if insts [j + 2 ].opname not in ("STORE_MAP" ,):
417
- return None
418
-
419
- collection_enum = CONST_COLLECTIONS .index ("CONST_MAP" )
420
-
421
- new_tokens = next_tokens [:i ]
422
- start_offset = insts [i ].offset
423
- new_tokens .append (
424
- Token (
425
- opname = "COLLECTION_START" ,
426
- attr = collection_enum ,
427
- pattr = "CONST_MAP" ,
428
- offset = f"{ start_offset } _0" ,
429
- linestart = insts [i ].starts_line ,
430
- has_arg = True ,
431
- has_extended_arg = False ,
432
- opc = self .opc ,
433
- optype = "pseudo" ,
434
- )
435
- )
436
- for j in range (i + 1 , collection_end , 3 ):
437
- new_tokens .append (
438
- Token (
439
- opname = "ADD_KEY" ,
440
- attr = insts [j + 1 ].argval ,
441
- pattr = insts [j + 1 ].argrepr ,
442
- offset = insts [j + 1 ].offset ,
443
- linestart = insts [j + 1 ].starts_line ,
444
- has_arg = True ,
445
- has_extended_arg = False ,
446
- opc = self .opc ,
447
- optype = "pseudo" ,
448
- )
449
- )
450
- new_tokens .append (
451
- Token (
452
- opname = "ADD_VALUE" ,
453
- attr = insts [j ].argval ,
454
- pattr = insts [j ].argrepr ,
455
- offset = insts [j ].offset ,
456
- linestart = insts [j ].starts_line ,
457
- has_arg = True ,
458
- has_extended_arg = False ,
459
- opc = self .opc ,
460
- optype = "pseudo" ,
461
- )
462
- )
463
- new_tokens .append (
464
- Token (
465
- opname = "BUILD_DICT_OLDER" ,
466
- attr = t .attr ,
467
- pattr = t .pattr ,
468
- offset = t .offset ,
469
- linestart = t .linestart ,
470
- has_arg = t .has_arg ,
471
- has_extended_arg = False ,
472
- opc = t .opc ,
473
- optype = "pseudo" ,
474
- )
475
- )
476
- return new_tokens
477
-
478
393
def ingest (
479
394
self , co , classname = None , code_objects = {}, show_asm = None
480
395
) -> Tuple [list , dict ]:
@@ -578,6 +493,7 @@ def ingest(
578
493
579
494
last_op_was_break = False
580
495
new_tokens = []
496
+
581
497
skip_end_offset = None
582
498
583
499
for i , inst in enumerate (self .insts ):
@@ -623,35 +539,18 @@ def ingest(
623
539
continue
624
540
625
541
elif opname in ("BUILD_MAP" ,):
626
- bound_map_from_insts_fn = (
627
- self .bound_map_from_inst_35
628
- if self .version >= (3 , 5 )
629
- else self .bound_map_from_inst_pre35
630
- )
631
- try_tokens = bound_map_from_insts_fn (
632
- self .insts ,
633
- new_tokens ,
634
- t ,
635
- i ,
636
- )
637
- if try_tokens is not None :
638
- if self .version < (3 , 5 ):
639
- assert try_tokens [- 1 ] == "BUILD_DICT_OLDER"
640
- prev_offset = inst .offset
641
- for j in range (i , len (self .insts )):
642
- if self .insts [j ].opname == "STORE_NAME" :
643
- new_tokens = try_tokens
644
- skip_end_offset = prev_offset
645
- # Set a hacky sentinal to indicate skipping to the
646
- # next instruction
647
- opname = "EXTENDED_ARG"
648
- break
649
- prev_offset = self .insts [j ].offset
650
- pass
651
- pass
652
- else :
542
+ if self .version >= (3 , 5 ):
543
+ try_tokens = self .bound_map_from_inst_35 (
544
+ self .insts ,
545
+ new_tokens ,
546
+ t ,
547
+ i ,
548
+ )
549
+ if try_tokens is not None :
653
550
new_tokens = try_tokens
654
551
continue
552
+ pass
553
+ pass
655
554
pass
656
555
657
556
argval = inst .argval
0 commit comments