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

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
This commit is contained in:
nobu 2015-08-22 06:45:44 +00:00
parent 2f8a4d317f
commit 3e6742cffe

View file

@ -8811,29 +8811,26 @@ rb_id_quote_unprintable(ID id)
static VALUE static VALUE
sym_inspect(VALUE sym) sym_inspect(VALUE sym)
{ {
VALUE str; VALUE str = rb_sym2str(sym);
const char *ptr; const char *ptr;
long len; long len;
char *dest; char *dest;
sym = rb_sym2str(sym); if (!rb_str_symname_p(str)) {
if (!rb_str_symname_p(sym)) { str = rb_str_inspect(str);
str = rb_str_inspect(sym);
len = RSTRING_LEN(str); len = RSTRING_LEN(str);
rb_str_resize(str, len + 1); rb_str_resize(str, len + 1);
dest = RSTRING_PTR(str); dest = RSTRING_PTR(str);
memmove(dest + 1, dest, len); memmove(dest + 1, dest, len);
dest[0] = ':';
} }
else { else {
rb_encoding *enc = STR_ENC_GET(sym); rb_encoding *enc = STR_ENC_GET(str);
ptr = RSTRING_PTR(sym); RSTRING_GETMEM(str, ptr, len);
len = RSTRING_LEN(sym);
str = rb_enc_str_new(0, len + 1, enc); str = rb_enc_str_new(0, len + 1, enc);
dest = RSTRING_PTR(str); dest = RSTRING_PTR(str);
dest[0] = ':';
memcpy(dest + 1, ptr, len); memcpy(dest + 1, ptr, len);
} }
dest[0] = ':';
return str; return str;
} }