diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2020-07-22 12:47:14 +0200 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-23 10:52:30 +0900 |
commit | 6a0cb1d649ecfc3e2af922c74ce82b3ff95fb12a (patch) | |
tree | 6483261e24d66c6592b8e3857ca388ff82cf120a /ext | |
parent | 5d04ac6ea2fefa4d6e4d22ab9c9903b8ff160167 (diff) | |
download | ruby-6a0cb1d649ecfc3e2af922c74ce82b3ff95fb12a.tar.gz |
Avoid allocating a string when dumping an anonymous module or class
Diffstat (limited to 'ext')
-rw-r--r-- | ext/objspace/objspace_dump.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index 95bd8ac8dd..2659404556 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -268,8 +268,11 @@ dump_object(VALUE obj, struct dump_config *dc) case T_CLASS: case T_MODULE: - if (dc->cur_obj_klass) - dump_append(dc, ", \"name\":\"%s\"", rb_class2name(obj)); + if (dc->cur_obj_klass) { + VALUE mod_name = rb_mod_name(obj); + if (!NIL_P(mod_name)) + dump_append(dc, ", \"name\":\"%s\"", RSTRING_PTR(mod_name)); + } break; case T_DATA: |