summaryrefslogtreecommitdiff
path: root/ext/-test-
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2021-08-26 10:06:32 -0400
committerPeter Zhu <peter@peterzhu.ca>2021-10-25 13:26:23 -0400
commita5b6598192c30187b19b892af3110a46f6a70d76 (patch)
tree4620f69a10659deb6f278b36c10ec7915194573e /ext/-test-
parent6374be5a8188ff5ed2c70b9f1d76672c87a0eda7 (diff)
[Feature #18239] Implement VWA for strings
This commit adds support for embedded strings with variable capacity and uses Variable Width Allocation to allocate strings.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4933
Diffstat (limited to 'ext/-test-')
-rw-r--r--ext/-test-/string/capacity.c9
-rw-r--r--ext/-test-/string/cstr.c10
2 files changed, 14 insertions, 5 deletions
diff --git a/ext/-test-/string/capacity.c b/ext/-test-/string/capacity.c
index cb8d2c2b3a..33b2023fd3 100644
--- a/ext/-test-/string/capacity.c
+++ b/ext/-test-/string/capacity.c
@@ -4,10 +4,11 @@
static VALUE
bug_str_capacity(VALUE klass, VALUE str)
{
- return
- STR_EMBED_P(str) ? INT2FIX(RSTRING_EMBED_LEN_MAX) : \
- STR_SHARED_P(str) ? INT2FIX(0) : \
- LONG2FIX(RSTRING(str)->as.heap.aux.capa);
+ if (!STR_EMBED_P(str) && STR_SHARED_P(str)) {
+ return INT2FIX(0);
+ }
+
+ return LONG2FIX(rb_str_capacity(str));
}
void
diff --git a/ext/-test-/string/cstr.c b/ext/-test-/string/cstr.c
index 4f837998d7..1eadb8b4fd 100644
--- a/ext/-test-/string/cstr.c
+++ b/ext/-test-/string/cstr.c
@@ -62,9 +62,13 @@ bug_str_unterminated_substring(VALUE str, VALUE vbeg, VALUE vlen)
if (RSTRING_LEN(str) < beg + len) rb_raise(rb_eIndexError, "end: %ld", beg + len);
str = rb_str_new_shared(str);
if (STR_EMBED_P(str)) {
+#if USE_RVARGC
+ RSTRING(str)->as.embed.len = (short)len;
+#else
RSTRING(str)->basic.flags &= ~RSTRING_EMBED_LEN_MASK;
RSTRING(str)->basic.flags |= len << RSTRING_EMBED_LEN_SHIFT;
- memmove(RSTRING(str)->as.ary, RSTRING(str)->as.ary + beg, len);
+#endif
+ memmove(RSTRING(str)->as.embed.ary, RSTRING(str)->as.embed.ary + beg, len);
}
else {
RSTRING(str)->as.heap.ptr += beg;
@@ -112,7 +116,11 @@ bug_str_s_cstr_noembed(VALUE self, VALUE str)
Check_Type(str, T_STRING);
FL_SET((str2), STR_NOEMBED);
memcpy(buf, RSTRING_PTR(str), capacity);
+#if USE_RVARGC
+ RBASIC(str2)->flags &= ~(STR_SHARED | FL_USER5 | FL_USER6);
+#else
RBASIC(str2)->flags &= ~RSTRING_EMBED_LEN_MASK;
+#endif
RSTRING(str2)->as.heap.aux.capa = capacity;
RSTRING(str2)->as.heap.ptr = buf;
RSTRING(str2)->as.heap.len = RSTRING_LEN(str);