зеркало из https://github.com/github/ruby.git
string.c: fix memsize of frozen shared string
* string.c (str_new4): copy the original capacity so that memsize of frozen shared string returns correct size. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
faaec02a2d
Коммит
4760b9824f
|
@ -1,3 +1,8 @@
|
|||
Wed Nov 27 02:26:58 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (str_new4): copy the original capacity so that memsize of
|
||||
frozen shared string returns correct size.
|
||||
|
||||
Wed Nov 27 02:20:13 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* array.c (rb_ary_hash): should not ignore the rest of recursive
|
||||
|
|
5
string.c
5
string.c
|
@ -749,6 +749,9 @@ str_new4(VALUE klass, VALUE str)
|
|||
STR_SET_SHARED(str2, shared); /* TODO: WB is not needed because str2 is *new* object */
|
||||
}
|
||||
else {
|
||||
if (!STR_ASSOC_P(str)) {
|
||||
RSTRING(str2)->as.heap.aux.capa = RSTRING(str)->as.heap.aux.capa;
|
||||
}
|
||||
STR_SET_SHARED(str, str2);
|
||||
}
|
||||
rb_enc_cr_str_exact_copy(str2, str);
|
||||
|
@ -879,7 +882,7 @@ rb_str_free(VALUE str)
|
|||
RUBY_FUNC_EXPORTED size_t
|
||||
rb_str_memsize(VALUE str)
|
||||
{
|
||||
if (!STR_EMBED_P(str) && !STR_SHARED_P(str)) {
|
||||
if (FL_TEST(str, STR_NOEMBED|ELTS_SHARED) == STR_NOEMBED) {
|
||||
return STR_HEAP_SIZE(str);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -24,6 +24,14 @@ class TestObjSpace < Test::Unit::TestCase
|
|||
ObjectSpace.memsize_of(//.match("")))
|
||||
end
|
||||
|
||||
def test_memsize_of_root_shared_string
|
||||
a = "hello" * 5
|
||||
b = a.dup
|
||||
c = nil
|
||||
ObjectSpace.each_object(String) {|x| break c = x if x == a and x.frozen?}
|
||||
assert_equal([0, 0, 26], [a, b, c].map {|x| ObjectSpace.memsize_of(x)})
|
||||
end
|
||||
|
||||
def test_argf_memsize
|
||||
size = ObjectSpace.memsize_of(ARGF)
|
||||
assert_kind_of(Integer, size)
|
||||
|
|
Загрузка…
Ссылка в новой задаче