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

ruby-changes:41700

From: nobu <ko1@a...>
Date: Mon, 8 Feb 2016 12:44:41 +0900 (JST)
Subject: [ruby-changes:41700] nobu:r53774 (trunk): string.c: remove magic number

nobu	2016-02-08 12:44:48 +0900 (Mon, 08 Feb 2016)

  New Revision: 53774

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

  Log:
    string.c: remove magic number
    
    * string.c (rb_str_dump): share same string literal instead of a
      magic number.

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 53773)
+++ string.c	(revision 53774)
@@ -5483,6 +5483,7 @@ rb_str_dump(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L5483
     char *q, *qend;
     VALUE result;
     int u8 = (encidx == rb_utf8_encindex());
+    static const char nonascii_suffix[] = ".force_encoding(\"%s\")";
 
     len = 2;			/* "" */
     p = RSTRING_PTR(str); pend = p + RSTRING_LEN(str);
@@ -5521,7 +5522,7 @@ rb_str_dump(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L5522
 	}
     }
     if (!rb_enc_asciicompat(enc)) {
-	len += 19;		/* ".force_encoding('')" */
+	len += strlen(nonascii_suffix) - rb_strlen_lit("%s");
 	len += strlen(enc->name);
     }
 
@@ -5595,7 +5596,7 @@ rb_str_dump(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L5596
     *q++ = '"';
     *q = '\0';
     if (!rb_enc_asciicompat(enc)) {
-	snprintf(q, qend-q, ".force_encoding(\"%s\")", enc->name);
+	snprintf(q, qend-q, nonascii_suffix, enc->name);
 	encidx = rb_ascii8bit_encindex();
     }
     OBJ_INFECT_RAW(result, str);

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

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