summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-22 06:45:44 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-22 06:45:44 (GMT)
commit3e6742cffe3d015d1128b9e665a00cee7b14177c (patch)
treeeb1a23b40d5ec1737df9c2bc2aa5e6f20341d62d /string.c
parent2f8a4d317f70f58e3008b2aa814e48a45c6427f6 (diff)
string.c: move common statement
* string.c (sym_inspect): move common statement and change variable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/string.c b/string.c
index f2a9b33..2563df6 100644
--- a/string.c
+++ b/string.c
@@ -8811,29 +8811,26 @@ rb_id_quote_unprintable(ID id)
static VALUE
sym_inspect(VALUE sym)
{
- VALUE str;
+ VALUE str = rb_sym2str(sym);
const char *ptr;
long len;
char *dest;
- sym = rb_sym2str(sym);
- if (!rb_str_symname_p(sym)) {
- str = rb_str_inspect(sym);
+ if (!rb_str_symname_p(str)) {
+ str = rb_str_inspect(str);
len = RSTRING_LEN(str);
rb_str_resize(str, len + 1);
dest = RSTRING_PTR(str);
memmove(dest + 1, dest, len);
- dest[0] = ':';
}
else {
- rb_encoding *enc = STR_ENC_GET(sym);
- ptr = RSTRING_PTR(sym);
- len = RSTRING_LEN(sym);
+ rb_encoding *enc = STR_ENC_GET(str);
+ RSTRING_GETMEM(str, ptr, len);
str = rb_enc_str_new(0, len + 1, enc);
dest = RSTRING_PTR(str);
- dest[0] = ':';
memcpy(dest + 1, ptr, len);
}
+ dest[0] = ':';
return str;
}