1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* regcomp.c (onig_region_memsize): implemented for memsize_of().

* ext/objspace/objspace.c (memsize_of): use it.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2011-12-15 04:15:54 +00:00
parent 15f26afdf0
commit 84dcc38273
5 changed files with 22 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Thu Dec 15 13:15:51 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* regcomp.c (onig_region_memsize): implemented for memsize_of().
* ext/objspace/objspace.c (memsize_of): use it.
Thu Dec 15 10:44:54 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc.

View file

@ -97,7 +97,7 @@ memsize_of(VALUE obj)
case T_MATCH:
if (RMATCH(obj)->rmatch) {
struct rmatch *rm = RMATCH(obj)->rmatch;
size += sizeof(struct re_registers); /* TODO: onig_region_memsize(&rm->regs); */
size += onig_region_memsize(&rm->regs);
size += sizeof(struct rmatch_offset) * rm->char_offset_num_allocated;
size += sizeof(struct rmatch);
}

View file

@ -5244,6 +5244,7 @@ size_t
onig_memsize(const regex_t *reg)
{
size_t size = sizeof(regex_t);
if (!reg) return 0;
if (IS_NOT_NULL(reg->p)) size += reg->alloc;
if (IS_NOT_NULL(reg->exact)) size += reg->exact_end - reg->exact;
if (IS_NOT_NULL(reg->int_map)) size += sizeof(int) * ONIG_CHAR_TABLE_SIZE;
@ -5254,6 +5255,15 @@ onig_memsize(const regex_t *reg)
return size;
}
size_t
onig_region_memsize(const OnigRegion *regs)
{
size_t size = sizeof(*regs);
if (!regs) return 0;
size += regs->allocated * (sizeof(*regs->beg) + sizeof(*regs->end));
return size;
}
#define REGEX_TRANSFER(to,from) do {\
(to)->state = ONIG_STATE_MODIFY;\
onig_free_body(to);\

View file

@ -842,6 +842,7 @@ typedef int (*ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE)(void);
extern int onigenc_property_list_init P_((ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE));
extern size_t onig_memsize P_((const regex_t *reg));
extern size_t onig_region_memsize P_((const struct re_registers *regs));
#if defined __GNUC__ && __GNUC__ >= 4
#pragma GCC visibility pop

View file

@ -17,6 +17,10 @@ class TestObjSpace < Test::Unit::TestCase
f.close
assert_kind_of(Integer, ObjectSpace.memsize_of(/a/.match("a")))
assert_kind_of(Integer, ObjectSpace.memsize_of(Struct.new(:a)))
assert_operator(ObjectSpace.memsize_of(Regexp.new("(a)"*1000).match("a"*1000)),
:>,
ObjectSpace.memsize_of(//.match("")))
end
def test_memsize_of_all