summaryrefslogtreecommitdiff
path: root/internal/hash.h
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-02-10 17:30:34 +0100
committerJean Boussier <[email protected]>2025-02-12 10:23:50 +0100
commitf32d5071b7b01f258eb45cf533496d82d5c0f6a1 ()
tree8d06f73cf4b023e1a990708add70118f47994829 /internal/hash.h
parentb8db606d2c721b4c3a439b9602771623ac01b288 (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: Merged: https://.com/ruby/ruby/pull/12730
-rw-r--r--internal/hash.h1
1 files changed, 1 insertions, 0 deletions
@@ -86,6 +86,7 @@ VALUE rb_hash_set_pair(VALUE hash, VALUE pair);
int rb_hash_stlike_delete(VALUE hash, st_data_t *pkey, st_data_t *pval);
int rb_hash_stlike_foreach_with_replace(VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg);
int rb_hash_stlike_update(VALUE hash, st_data_t key, st_update_callback_func *func, st_data_t arg);
VALUE rb_ident_hash_new_with_size(st_index_t size);
void rb_hash_free(VALUE hash);
RUBY_EXTERN VALUE rb_cHash_empty_frozen;