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

ruby-changes:39589

From: nobu <ko1@a...>
Date: Mon, 24 Aug 2015 16:01:44 +0900 (JST)
Subject: [ruby-changes:39589] nobu:r51670 (trunk): encoding.c: find encoding index

nobu	2015-08-24 16:01:22 +0900 (Mon, 24 Aug 2015)

  New Revision: 51670

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

  Log:
    encoding.c: find encoding index
    
    * encoding.c (rb_locale_encindex): find encoding index without
      making a string object every time.  [ruby-core:58160] [Bug #9080]

  Modified files:
    trunk/ChangeLog
    trunk/encoding.c
    trunk/localeinit.c
    trunk/miniinit.c
Index: encoding.c
===================================================================
--- encoding.c	(revision 51669)
+++ encoding.c	(revision 51670)
@@ -1275,16 +1275,14 @@ rb_usascii_encindex(void) https://github.com/ruby/ruby/blob/trunk/encoding.c#L1275
     return ENCINDEX_US_ASCII;
 }
 
+int rb_locale_charmap_index(void);
+
 int
 rb_locale_encindex(void)
 {
-    VALUE charmap = rb_locale_charmap(rb_cEncoding);
-    int idx;
+    int idx = rb_locale_charmap_index();
 
-    if (NIL_P(charmap))
-        idx = ENCINDEX_US_ASCII;
-    else if ((idx = rb_enc_find_index(StringValueCStr(charmap))) < 0)
-        idx = ENCINDEX_ASCII;
+    if (idx < 0) idx = ENCINDEX_ASCII;
 
     if (rb_enc_registered("locale") < 0) {
 # if defined _WIN32
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51669)
+++ ChangeLog	(revision 51670)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Aug 24 16:01:19 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* encoding.c (rb_locale_encindex): find encoding index without
+	  making a string object every time.  [ruby-core:58160] [Bug #9080]
+
 Sat Aug 22 15:43:12 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_eval.c (check_funcall_failed, check_funcall_missing): cache
Index: miniinit.c
===================================================================
--- miniinit.c	(revision 51669)
+++ miniinit.c	(revision 51670)
@@ -20,7 +20,14 @@ const char ruby_initial_load_paths[] = " https://github.com/ruby/ruby/blob/trunk/miniinit.c#L20
 VALUE
 rb_locale_charmap(VALUE klass)
 {
-    return rb_usascii_str_new2("ASCII-8BIT");
+    /* never used */
+    return Qnil;
+}
+
+int
+rb_locale_charmap_index(void)
+{
+    return -1;
 }
 
 int
Index: localeinit.c
===================================================================
--- localeinit.c	(revision 51669)
+++ localeinit.c	(revision 51670)
@@ -22,8 +22,8 @@ https://github.com/ruby/ruby/blob/trunk/localeinit.c#L22
 #define CP_FORMAT(buf, codepage) snprintf(buf, sizeof(buf), "CP%u", (codepage))
 #endif
 
-VALUE
-rb_locale_charmap(VALUE klass)
+static VALUE
+locale_charmap(VALUE (*conv)(const char *))
 {
 #if defined NO_LOCALE_CHARMAP
 # error NO_LOCALE_CHARMAP defined
@@ -40,16 +40,34 @@ rb_locale_charmap(VALUE klass) https://github.com/ruby/ruby/blob/trunk/localeinit.c#L40
 	CP_FORMAT(cp, codepage);
 	codeset = cp;
     }
-    return rb_usascii_str_new2(codeset);
+    return (*conv)(codeset);
 #elif defined HAVE_LANGINFO_H
     char *codeset;
     codeset = nl_langinfo(CODESET);
-    return rb_usascii_str_new2(codeset);
+    return (*conv)(codeset);
 #else
-    return Qnil;
+    return ENCINDEX_US_ASCII;
 #endif
 }
 
+VALUE
+rb_locale_charmap(VALUE klass)
+{
+    return locale_charmap(rb_usascii_str_new_cstr);
+}
+
+static VALUE
+enc_find_index(const char *name)
+{
+    return (VALUE)rb_enc_find_index(name);
+}
+
+int
+rb_locale_charmap_index(VALUE klass)
+{
+    return (int)locale_charmap(enc_find_index);
+}
+
 int
 Init_enc_set_filesystem_encoding(void)
 {

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

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