McRogueFace/src/tiled
John McCardle 182da6230d Fast path for hot property getters: stop importing mcrfpy per call; closes #331
Replace the PyImport_ImportModule("mcrfpy") + PyObject_GetAttrString +
full type-call ceremony with direct &mcrfpydef::PyXType references
(safe since all PyTypeObjects are inline C++17 definitions) in every
non-init call site:

- UIDrawable: get_pos/get_origin/get_global_pos now allocate via
  PyVector(...).pyObject(); set_pos/set_origin check the Vector type
  directly.
- GridLayers: ColorLayer at/subscript wrap via PyColor(...).pyObject()
  (also fixes a module refcount leak per read); set/fill/fill_rect,
  draw_fov/apply_perspective color parsing, Entity/Texture/HeightMap
  instance checks, and TileLayer texture get/set use direct type refs.
- UIGrid init layers=, add_layer/remove_layer/layer(), Grid.layers
  getter: direct ColorLayer/TileLayer type refs.
- PyTileSetFile.to_texture, PyLdtkProject.tileset: direct type refs.

Benchmark (tests/benchmarks/issue_331_property_read_bench.py, 200k
reads, release build):
  frame.pos              559 ns -> 65 ns/read  (8.6x)
  frame.origin           571 ns -> 64 ns/read  (8.9x)
  frame.global_position  589 ns -> 66 ns/read  (8.9x)
  ColorLayer.at          608 ns -> 262 ns/read (2.3x)

Test suite: 304/304 pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DK5DHgRDNGmpN54vnEHAot
2026-07-08 21:58:50 -04:00
..
PyTileMapFile.cpp Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00
PyTileMapFile.h Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00
PyTileSetFile.cpp Fast path for hot property getters: stop importing mcrfpy per call; closes #331 2026-07-08 21:58:50 -04:00
PyTileSetFile.h Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00
PyWangSet.cpp Check Python C-API returns in terrain_enum builders; closes #322 2026-06-26 23:52:38 -04:00
PyWangSet.h Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00
TiledParse.cpp Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00
TiledParse.h Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00
TiledTypes.h Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00
WangResolve.cpp Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00
WangResolve.h Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00