Skip to content

Commit

Permalink
WITH_VAR to reduce same calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Oct 25, 2024
1 parent 990a538 commit bd901d4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion vm_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ extern bool rb_vmdebug_stack_dump_raw(const rb_execution_context_t *ec, const rb
extern bool rb_vmdebug_debug_print_pre(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, const VALUE *_pc, FILE *);
extern bool rb_vmdebug_debug_print_post(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, FILE *);

#define SDR() rb_vmdebug_stack_dump_raw(GET_EC(), GET_EC()->cfp, stderr)
#define SDR() WITH_EC(ec) {rb_vmdebug_stack_dump_raw(ec, ec->cfp, stderr)}
#define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_EC(), (cfp), stderr)
bool rb_vm_bugreport(const void *, FILE *);
typedef void (*ruby_sighandler_t)(int);
Expand Down Expand Up @@ -1916,6 +1916,13 @@ RUBY_EXTERN unsigned int ruby_vm_event_local_num;
#define GET_THREAD() rb_current_thread()
#define GET_EC() rb_current_execution_context(true)

#define WITH_VAR(type, var, expr) \
for (type var = (expr), const *var ## _once = &var; var ## _once; var ## _once = 0)
#define WITH_VM(var) WITH_VAR(rb_vm_t *, var, GET_VM())
#define WITH_RACTOR(var) WITH_VAR(rb_ractor_t *, var, GET_RACTOR())
#define WITH_THREAD(var) WITH_VAR(rb_thread_t *, var, GET_THREAD())
#define WITH_EC(var) WITH_VAR(rb_execution_context_t *, var, GET_EC())

static inline rb_thread_t *
rb_ec_thread_ptr(const rb_execution_context_t *ec)
{
Expand Down

0 comments on commit bd901d4

Please sign in to comment.