diff options
| author | Kevin Menard <kevin@nirvdrum.com> | 2024-08-02 15:45:22 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-02 15:45:22 -0400 |
| commit | 04a6165ac07f8f2107fbbd3a5665944fb27bc092 (patch) | |
| tree | b9cf3af94f306d4f862979f5bcc717a938bef2ac /string.c | |
| parent | 3f93ef06a852af3f44d3c7a2ed62a670f9c3ff29 (diff) | |
YJIT: Enhance the `String#<<` method substitution to handle integer codepoint values. (#11032)
* Document why we need to explicitly spill registers.
* Simplify passing a byte value to `str_buf_cat`.
* YJIT: Enhance the `String#<<` method substitution to handle integer codepoint values.
* YJIT: Move runtime type check into YJIT.
Performing the check in YJIT means we can make assumptions about the type. It also improves correctness of stack traces in cases where the codepoint argument is not a String or a Fixnum.
Notes
Notes:
Merged-By: maximecb <maximecb@ruby-lang.org>
Diffstat (limited to 'string.c')
| -rw-r--r-- | string.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -3375,8 +3375,7 @@ rb_str_buf_cat_byte(VALUE str, unsigned char byte) } else { // If there's not enough string_capacity, make a call into the general string concatenation function. - char buf[1] = {byte}; - str_buf_cat(str, buf, 1); + str_buf_cat(str, (char *)&byte, 1); } // If the code range is already known, we can derive the resulting code range cheaply by looking at the byte we @@ -12297,6 +12296,23 @@ rb_enc_interned_str_cstr(const char *ptr, rb_encoding *enc) return rb_enc_interned_str(ptr, strlen(ptr), enc); } +#if USE_YJIT +void +rb_yjit_str_concat_codepoint(VALUE str, VALUE codepoint) +{ + if (RB_LIKELY(ENCODING_GET_INLINED(str) == rb_ascii8bit_encindex())) { + ssize_t code = RB_NUM2SSIZE(codepoint); + + if (RB_LIKELY(code >= 0 && code < 0xff)) { + rb_str_buf_cat_byte(str, (char) code); + return; + } + } + + rb_str_concat(str, codepoint); +} +#endif + void Init_String(void) { |
