[前][次][番号順一覧][スレッド一覧]

ruby-changes:39585

From: nobu <ko1@a...>
Date: Sat, 22 Aug 2015 15:45:55 +0900 (JST)
Subject: [ruby-changes:39585] nobu:r51666 (trunk): string.c: move common statement

nobu	2015-08-22 15:45:44 +0900 (Sat, 22 Aug 2015)

  New Revision: 51666

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51666

  Log:
    string.c: move common statement
    
    * string.c (sym_inspect): move common statement and change
      variable.

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 51665)
+++ string.c	(revision 51666)
@@ -8811,29 +8811,26 @@ rb_id_quote_unprintable(ID id) https://github.com/ruby/ruby/blob/trunk/string.c#L8811
 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;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]