diff options
author | Alan Wu <[email protected]> | 2024-10-11 10:22:44 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-10-11 10:22:44 -0400 |
commit | 11e7ab79deb5935573d15ba4f33fc41e5c2b7522 (patch) | |
tree | 1cfc9e22733dc2f097db6fda74539feb014fe411 /vm_eval.c | |
parent | 372bb990ac5ea8e348b9187b53d108d06049e6a3 (diff) |
Remove 1 allocation in Enumerable#each_with_index (#11868)
* Remove 1 allocation in Enumerable#each_with_index
Previously, each call to Enumerable#each_with_index allocates 2
objects, one for the counting index, the other an imemo_ifunc passed
to `self.each` as a block.
Use `struct vm_ifunc::data` to hold the counting index directly to
remove 1 allocation.
* [DOC] Brief summary for usages of `struct vm_ifunc`
Notes
Notes:
Merged-By: maximecb <[email protected]>
Diffstat (limited to 'vm_eval.c')
-rw-r--r-- | vm_eval.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -2702,6 +2702,17 @@ rb_current_realfilepath(void) return Qnil; } +// Assert that an internal function is running and return +// the imemo object that represents it. +struct vm_ifunc * +rb_current_ifunc(void) +{ + // Search VM_FRAME_MAGIC_IFUNC to see ifunc imemos put on the iseq field. + VALUE ifunc = (VALUE)GET_EC()->cfp->iseq; + RUBY_ASSERT_ALWAYS(imemo_type_p(ifunc, imemo_ifunc)); + return (struct vm_ifunc *)ifunc; +} + void Init_vm_eval(void) { |