зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
86bbfdadf3
Коммит
faf295f1e1
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
Tue Aug 2 15:53:37 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* 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 <nobu@ruby-lang.org>
|
||||
|
||||
* hash.c (recursive_hash): hash value of emptied hash should be
|
||||
|
|
24
encoding.c
24
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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче