Skip to content

Commit

Permalink
Rewrite MMTk-specific code with WHEN_USING_MMTK
Browse files Browse the repository at this point in the history
When the "#if USE_MMTK" directive and the `if (rb_mmtk_enabled_p())`
statement are used together, it will be very complicated and confusing.
We rewrite `string.c` using the convenient `WHEN_USING_MMTK`,
`WHEN_NOT_USING_MMTK` and `WHEN_USING_MMTK2` macros when possible.

This commit does not change the semantics of the existing code in
`string.c`.
  • Loading branch information
wks committed Sep 12, 2024
1 parent 69db488 commit cba8733
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 168 deletions.
4 changes: 4 additions & 0 deletions internal/mmtk_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

#if USE_MMTK
#define IF_USE_MMTK(a) a
#define IF_NOT_USE_MMTK(a)
#define IF_USE_MMTK2(a, b) a
#define WHEN_USING_MMTK(a) if (rb_mmtk_enabled_p()) { a }
#define WHEN_NOT_USING_MMTK(a) if (!rb_mmtk_enabled_p()) { a }
#define WHEN_USING_MMTK2(a, b) if (rb_mmtk_enabled_p()) { a } else { b }
#else
#define IF_USE_MMTK(a)
#define IF_NOT_USE_MMTK(a) a
#define IF_USE_MMTK2(a, b) b
#define WHEN_USING_MMTK(a)
#define WHEN_NOT_USING_MMTK(a) a
#define WHEN_USING_MMTK2(a, b) b
#endif

Expand Down
Loading

0 comments on commit cba8733

Please sign in to comment.