From faf295f1e1467b6f4e088877db258be03c7be4f4 Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 2 Aug 2011 07:35:21 +0000 Subject: [PATCH] * encoding.c (str_to_encoding): rename from to_encoding and use str_to_encindex. * encoding.c (str_to_encindex): split from to_encoding. * encoding.c (rb_to_encoding): use str_to_encoding. * encoding.c (rb_obj_encoding): don't bypass rb_encoding*. If it uses rb_encoding*, it bypass encindex. If it uses encindex, it doesn't bypass. * encoding.c (enc_find): add shortcut for encoding object, use str_to_encindex, and avoid bypass rb_encoding*. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 16 ++++++++++++++++ encoding.c | 24 ++++++++++++++++-------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3690ea62b1..5beeb604f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +Tue Aug 2 15:53:37 2011 NARUSE, Yui + + * encoding.c (str_to_encoding): rename from to_encoding and + use str_to_encindex. + + * encoding.c (str_to_encindex): split from to_encoding. + + * encoding.c (rb_to_encoding): use str_to_encoding. + + * encoding.c (rb_obj_encoding): don't bypass rb_encoding*. + If it uses rb_encoding*, it bypass encindex. If it uses encindex, + it doesn't bypass. + + * encoding.c (enc_find): add shortcut for encoding object, use + str_to_encindex, and avoid bypass rb_encoding*. + Tue Aug 2 12:03:16 2011 Nobuyoshi Nakada * hash.c (recursive_hash): hash value of emptied hash should be diff --git a/encoding.c b/encoding.c index 0b6bf96bc5..fca7e1fea6 100644 --- a/encoding.c +++ b/encoding.c @@ -159,8 +159,8 @@ rb_to_encoding_index(VALUE enc) return rb_enc_find_index(StringValueCStr(enc)); } -static rb_encoding * -to_encoding(VALUE enc) +static int +str_to_encindex(VALUE enc) { int idx; @@ -172,14 +172,20 @@ to_encoding(VALUE enc) if (idx < 0) { rb_raise(rb_eArgError, "unknown encoding name - %s", RSTRING_PTR(enc)); } - return rb_enc_from_index(idx); + return idx; +} + +static rb_encoding * +str_to_encoding(VALUE enc) +{ + return rb_enc_from_index(str_to_encindex(enc)); } rb_encoding * rb_to_encoding(VALUE enc) { if (enc_check_encoding(enc) >= 0) return RDATA(enc)->data; - return to_encoding(enc); + return str_to_encoding(enc); } void @@ -823,11 +829,11 @@ rb_enc_copy(VALUE obj1, VALUE obj2) VALUE rb_obj_encoding(VALUE obj) { - rb_encoding *enc = rb_enc_get(obj); - if (!enc) { + int idx = rb_enc_get_index(obj); + if (idx < 0) { rb_raise(rb_eTypeError, "unknown encoding"); } - return rb_enc_from_encoding(enc); + return rb_enc_from_encoding_index(idx); } int @@ -1045,7 +1051,9 @@ enc_list(VALUE klass) static VALUE enc_find(VALUE klass, VALUE enc) { - return rb_enc_from_encoding(rb_to_encoding(enc)); + if (!SPECIAL_CONST_P(enc) && BUILTIN_TYPE(enc) == T_DATA && is_data_encoding(enc)) + return enc; + return rb_enc_from_encoding_index(str_to_encindex(enc)); } /*