diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-06-06 10:19:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-06 10:19:20 -0400 |
commit | 7577c101ed6452de3e72fadb43db595946acc701 (patch) | |
tree | deed85a09fc431132145897d7e1982fd61c74e0c /ext | |
parent | fae2f80d06f5058b40e91f62ba27fb01f2463d12 (diff) | |
download | ruby-7577c101ed6452de3e72fadb43db595946acc701.tar.gz |
Unify length field for embedded and heap strings (#7908)
* Unify length field for embedded and heap strings
The length field is of the same type and position in RString for both
embedded and heap allocated strings, so we can unify it.
* Remove RSTRING_EMBED_LEN
Diffstat (limited to 'ext')
-rw-r--r-- | ext/-test-/string/cstr.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/ext/-test-/string/cstr.c b/ext/-test-/string/cstr.c index ecca793145..b0b1ef5374 100644 --- a/ext/-test-/string/cstr.c +++ b/ext/-test-/string/cstr.c @@ -61,13 +61,12 @@ bug_str_unterminated_substring(VALUE str, VALUE vbeg, VALUE vlen) if (RSTRING_LEN(str) < beg) rb_raise(rb_eIndexError, "beg: %ld", beg); if (RSTRING_LEN(str) < beg + len) rb_raise(rb_eIndexError, "end: %ld", beg + len); str = rb_str_new_shared(str); + RSTRING(str)->len = len; if (STR_EMBED_P(str)) { - RSTRING(str)->as.embed.len = (short)len; memmove(RSTRING(str)->as.embed.ary, RSTRING(str)->as.embed.ary + beg, len); } else { RSTRING(str)->as.heap.ptr += beg; - RSTRING(str)->as.heap.len = len; } return str; } @@ -114,7 +113,7 @@ bug_str_s_cstr_noembed(VALUE self, VALUE str) RBASIC(str2)->flags &= ~(STR_SHARED | FL_USER5 | FL_USER6); RSTRING(str2)->as.heap.aux.capa = capacity; RSTRING(str2)->as.heap.ptr = buf; - RSTRING(str2)->as.heap.len = RSTRING_LEN(str); + RSTRING(str2)->len = RSTRING_LEN(str); TERM_FILL(RSTRING_END(str2), TERM_LEN(str)); return str2; } |