From a31cc60806c5b7bacc25f580aa58d0cf492964b6 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 24 Aug 2015 07:01:22 +0000 Subject: 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 --- encoding.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'encoding.c') diff --git a/encoding.c b/encoding.c index b4ee0c8de2..298ff0f1b5 100644 --- a/encoding.c +++ b/encoding.c @@ -1275,16 +1275,14 @@ rb_usascii_encindex(void) 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 -- cgit v1.2.3