MCPcopy Index your code
hub / github.com/python/mypy / emit_inc_ref

Method emit_inc_ref

mypyc/codegen/emit.py:584–609  ·  view source on GitHub ↗

Increment reference count of C expression `dest`. For composite unboxed structures (e.g. tuples) recursively increment reference counts for each component. If rare is True, optimize for code size and compilation speed.

(self, dest: str, rtype: RType, *, rare: bool = False)

Source from the content-addressed store, hash-verified

582 )
583
584 def emit_inc_ref(self, dest: str, rtype: RType, *, rare: bool = False) -> None:
585 """Increment reference count of C expression `dest`.
586
587 For composite unboxed structures (e.g. tuples) recursively
588 increment reference counts for each component.
589
590 If rare is True, optimize for code size and compilation speed.
591 """
592 if is_int_rprimitive(rtype):
593 if rare:
594 self.emit_line("CPyTagged_IncRef(%s);" % dest)
595 else:
596 self.emit_line("CPyTagged_INCREF(%s);" % dest)
597 elif isinstance(rtype, RTuple):
598 for i, item_type in enumerate(rtype.types):
599 self.emit_inc_ref(f"{dest}.f{i}", item_type)
600 elif isinstance(rtype, RVec):
601 prefix = VEC_MACRO_PREFIX[rtype._ctype]
602 self.emit_line(f"{prefix}_INCREF({dest});")
603 elif not rtype.is_unboxed:
604 # Always inline, since this is a simple but very hot op
605 if rtype.may_be_immortal or not HAVE_IMMORTAL:
606 self.emit_line("CPy_INCREF(%s);" % dest)
607 else:
608 self.emit_line("CPy_INCREF_NO_IMM(%s);" % dest)
609 # Otherwise assume it's an unboxed, pointerless value and do nothing.
610
611 def emit_dec_ref(
612 self, dest: str, rtype: RType, *, is_xdec: bool = False, rare: bool = False

Callers 10

emit_unboxMethod · 0.95
emit_boxMethod · 0.95
test_emit_inc_ref_intMethod · 0.45
generate_getterFunction · 0.45
generate_setterFunction · 0.45

Calls 4

emit_lineMethod · 0.95
is_int_rprimitiveFunction · 0.90
isinstanceFunction · 0.85
enumerateFunction · 0.85

Tested by 6

test_emit_inc_ref_intMethod · 0.36