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

Function emit_reuse_dealloc

mypyc/codegen/emitclass.py:974–992  ·  view source on GitHub ↗

Emit code to deallocate object by putting it to per-type free list. The free "list" currently can have up to one object.

(cl: ClassIR, emitter: Emitter)

Source from the content-addressed store, hash-verified

972
973
974def emit_reuse_dealloc(cl: ClassIR, emitter: Emitter) -> None:
975 """Emit code to deallocate object by putting it to per-type free list.
976
977 The free "list" currently can have up to one object.
978 """
979 prefix = cl.name_prefix(emitter.names)
980 emitter.emit_line(f"if ({prefix}_free_instance == NULL) {{")
981 emitter.emit_line(f"{prefix}_free_instance = self;")
982
983 # Clear attributes and free referenced objects.
984
985 emit_clear_bitmaps(cl, emitter)
986
987 for base in reversed(cl.base_mro):
988 for attr, rtype in base.attributes.items():
989 emitter.emit_reuse_clear(f"self->{emitter.attr(attr)}", rtype)
990
991 emitter.emit_line("return;")
992 emitter.emit_line("}")
993
994
995def generate_finalize_for_class(

Callers 1

Calls 7

emit_clear_bitmapsFunction · 0.85
reversedFunction · 0.85
name_prefixMethod · 0.80
emit_reuse_clearMethod · 0.80
attrMethod · 0.80
emit_lineMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…