diff options
author | Jean Boussier <[email protected]> | 2025-02-10 17:30:34 +0100 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-02-12 10:23:50 +0100 |
commit | f32d5071b7b01f258eb45cf533496d82d5c0f6a1 (patch) | |
tree | 8d06f73cf4b023e1a990708add70118f47994829 /include/ruby/internal/core | |
parent | b8db606d2c721b4c3a439b9602771623ac01b288 (diff) |
Elide string allocation when using `String#gsub` in MAP mode
If the provided Hash doesn't have a default proc, we know for
sure that we'll never call into user provided code, hence the
string we allocate to access the Hash can't possibly escape.
So we don't actually have to allocate it, we can use a fake_str,
AKA a stack allocated string.
```
compare-ruby: ruby 3.5.0dev (2025-02-10T13:47:44Z master 3fb455adab) +PRISM [arm64-darwin23]
built-ruby: ruby 3.5.0dev (2025-02-10T17:09:52Z opt-gsub-alloc ea5c28958f) +PRISM [arm64-darwin23]
warming up....
| |compare-ruby|built-ruby|
|:----------------|-----------:|---------:|
|escape | 3.374k| 3.722k|
| | -| 1.10x|
|escape_bin | 5.469k| 6.587k|
| | -| 1.20x|
|escape_utf8 | 3.465k| 3.734k|
| | -| 1.08x|
|escape_utf8_bin | 5.752k| 7.283k|
| | -| 1.27x|
```
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12730
Diffstat (limited to 'include/ruby/internal/core')
0 files changed, 0 insertions, 0 deletions