summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2022-07-06 12:31:54 +0200
committerJean Boussier <jean.boussier@gmail.com>2022-07-06 17:25:58 +0200
commit906f7cb3e7e6de2b75dc4a4a3c09f98d8bf28388 (patch)
treefe7dd9fc9424564fb9d10222d3df0591c76b0444 /vm_insnhelper.c
parent9641f23316d7eeb445cfc31191fe746865454671 (diff)
vm_opt_ltlt: call rb_str_buf_append directly if RHS is a String
`rb_str_concat` does a lot of type checking we can easily bypass. ``` | |compare-ruby|built-ruby| |:--------------|-----------:|---------:| |string_concat | 362.007k| 398.965k| | | -| 1.10x| ```
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6095
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index abc8aef053..8db11be5e5 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -5376,7 +5376,11 @@ vm_opt_ltlt(VALUE recv, VALUE obj)
}
else if (RBASIC_CLASS(recv) == rb_cString &&
BASIC_OP_UNREDEFINED_P(BOP_LTLT, STRING_REDEFINED_OP_FLAG)) {
- return rb_str_concat(recv, obj);
+ if (LIKELY(RB_TYPE_P(obj, T_STRING))) {
+ return rb_str_buf_append(recv, obj);
+ } else {
+ return rb_str_concat(recv, obj);
+ }
}
else if (RBASIC_CLASS(recv) == rb_cArray &&
BASIC_OP_UNREDEFINED_P(BOP_LTLT, ARRAY_REDEFINED_OP_FLAG)) {