1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/-test-/string/capacity.c
Peter Zhu a5b6598192 [Feature #18239] Implement VWA for strings
This commit adds support for embedded strings with variable capacity and
uses Variable Width Allocation to allocate strings.
2021-10-25 13:26:23 -04:00

18 lines
349 B
C

#include "ruby.h"
#include "internal/string.h"
static VALUE
bug_str_capacity(VALUE klass, VALUE str)
{
if (!STR_EMBED_P(str) && STR_SHARED_P(str)) {
return INT2FIX(0);
}
return LONG2FIX(rb_str_capacity(str));
}
void
Init_string_capacity(VALUE klass)
{
rb_define_singleton_method(klass, "capacity", bug_str_capacity, 1);
}