Skip to content

Commit bd901d4

Browse files
committed
WITH_VAR to reduce same calls
1 parent 990a538 commit bd901d4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

vm_core.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ extern bool rb_vmdebug_stack_dump_raw(const rb_execution_context_t *ec, const rb
17981798
extern bool rb_vmdebug_debug_print_pre(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, const VALUE *_pc, FILE *);
17991799
extern bool rb_vmdebug_debug_print_post(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, FILE *);
18001800

1801-
#define SDR() rb_vmdebug_stack_dump_raw(GET_EC(), GET_EC()->cfp, stderr)
1801+
#define SDR() WITH_EC(ec) {rb_vmdebug_stack_dump_raw(ec, ec->cfp, stderr)}
18021802
#define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_EC(), (cfp), stderr)
18031803
bool rb_vm_bugreport(const void *, FILE *);
18041804
typedef void (*ruby_sighandler_t)(int);
@@ -1916,6 +1916,13 @@ RUBY_EXTERN unsigned int ruby_vm_event_local_num;
19161916
#define GET_THREAD() rb_current_thread()
19171917
#define GET_EC() rb_current_execution_context(true)
19181918

1919+
#define WITH_VAR(type, var, expr) \
1920+
for (type var = (expr), const *var ## _once = &var; var ## _once; var ## _once = 0)
1921+
#define WITH_VM(var) WITH_VAR(rb_vm_t *, var, GET_VM())
1922+
#define WITH_RACTOR(var) WITH_VAR(rb_ractor_t *, var, GET_RACTOR())
1923+
#define WITH_THREAD(var) WITH_VAR(rb_thread_t *, var, GET_THREAD())
1924+
#define WITH_EC(var) WITH_VAR(rb_execution_context_t *, var, GET_EC())
1925+
19191926
static inline rb_thread_t *
19201927
rb_ec_thread_ptr(const rb_execution_context_t *ec)
19211928
{

0 commit comments

Comments
 (0)