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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
73600fd6f8
commit
7a89049a76
@ -1,3 +1,8 @@
|
|||||||
|
Mon Aug 24 16:01:19 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Sat Aug 22 15:43:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* vm_eval.c (check_funcall_failed, check_funcall_missing): cache
|
* vm_eval.c (check_funcall_failed, check_funcall_missing): cache
|
||||||
|
10
encoding.c
10
encoding.c
@ -1275,16 +1275,14 @@ rb_usascii_encindex(void)
|
|||||||
return ENCINDEX_US_ASCII;
|
return ENCINDEX_US_ASCII;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rb_locale_charmap_index(void);
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_locale_encindex(void)
|
rb_locale_encindex(void)
|
||||||
{
|
{
|
||||||
VALUE charmap = rb_locale_charmap(rb_cEncoding);
|
int idx = rb_locale_charmap_index();
|
||||||
int idx;
|
|
||||||
|
|
||||||
if (NIL_P(charmap))
|
if (idx < 0) idx = ENCINDEX_ASCII;
|
||||||
idx = ENCINDEX_US_ASCII;
|
|
||||||
else if ((idx = rb_enc_find_index(StringValueCStr(charmap))) < 0)
|
|
||||||
idx = ENCINDEX_ASCII;
|
|
||||||
|
|
||||||
if (rb_enc_registered("locale") < 0) {
|
if (rb_enc_registered("locale") < 0) {
|
||||||
# if defined _WIN32
|
# if defined _WIN32
|
||||||
|
28
localeinit.c
28
localeinit.c
@ -22,8 +22,8 @@
|
|||||||
#define CP_FORMAT(buf, codepage) snprintf(buf, sizeof(buf), "CP%u", (codepage))
|
#define CP_FORMAT(buf, codepage) snprintf(buf, sizeof(buf), "CP%u", (codepage))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VALUE
|
static VALUE
|
||||||
rb_locale_charmap(VALUE klass)
|
locale_charmap(VALUE (*conv)(const char *))
|
||||||
{
|
{
|
||||||
#if defined NO_LOCALE_CHARMAP
|
#if defined NO_LOCALE_CHARMAP
|
||||||
# error NO_LOCALE_CHARMAP defined
|
# error NO_LOCALE_CHARMAP defined
|
||||||
@ -40,16 +40,34 @@ rb_locale_charmap(VALUE klass)
|
|||||||
CP_FORMAT(cp, codepage);
|
CP_FORMAT(cp, codepage);
|
||||||
codeset = cp;
|
codeset = cp;
|
||||||
}
|
}
|
||||||
return rb_usascii_str_new2(codeset);
|
return (*conv)(codeset);
|
||||||
#elif defined HAVE_LANGINFO_H
|
#elif defined HAVE_LANGINFO_H
|
||||||
char *codeset;
|
char *codeset;
|
||||||
codeset = nl_langinfo(CODESET);
|
codeset = nl_langinfo(CODESET);
|
||||||
return rb_usascii_str_new2(codeset);
|
return (*conv)(codeset);
|
||||||
#else
|
#else
|
||||||
return Qnil;
|
return ENCINDEX_US_ASCII;
|
||||||
#endif
|
#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
|
int
|
||||||
Init_enc_set_filesystem_encoding(void)
|
Init_enc_set_filesystem_encoding(void)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,14 @@ const char ruby_initial_load_paths[] = "";
|
|||||||
VALUE
|
VALUE
|
||||||
rb_locale_charmap(VALUE klass)
|
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
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user